forked from mjordan/islandora_workbench_integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
islandora_workbench_integration.module
54 lines (47 loc) · 1.54 KB
/
islandora_workbench_integration.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* @file
* Contains islandora_workbench_integration.module.
*
* This module adds views and REST interfaces for Islandora Workbench.
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\node\Entity\NodeType;
use Drupal\media\Entity\MediaType;
/**
* Implements hook_ENTITY_TYPE_presave() for node entities.
*/
function islandora_workbench_integration_node_presave(EntityInterface $node) {
// Get the content type of the node.
$content_type = NodeType::load($node->bundle());
// Check if the content type exists and if the "Create new revision"
// option is enabled.
if ($content_type && $content_type->shouldCreateNewRevision()) {
// The "Create new revision" option is enabled.
$node->setNewRevision(TRUE);
$node->setRevisionCreationTime(Drupal::time()->getRequestTime());
}
else {
// The "Create new revision" option is disabled.
$node->setNewRevision(FALSE);
}
}
/**
* Implements hook_ENTITY_TYPE_presave() for media entities.
*/
function islandora_workbench_integration_media_presave(EntityInterface $media) {
// Get the bundle (media type) of the media entity.
$bundle = $media->bundle();
// Load the media type entity.
$media_type = MediaType::load($bundle);
// Check if the media type exists and if the "Create new revision"
// option is enabled.
if ($media_type && $media_type->shouldCreateNewRevision()) {
// The "Create new revision" option is enabled.
$media->setNewRevision(TRUE);
}
else {
// The "Create new revision" option is disabled.
$media->setNewRevision(FALSE);
}
}