-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathislandora_rdm_datacite.module
executable file
·85 lines (72 loc) · 2.58 KB
/
islandora_rdm_datacite.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* @file
* Contains islandora_rdm_datacite.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\islandora\Plugin\ContextReaction\DeleteReaction;
/**
* Implements hook_help().
*/
function islandora_rdm_datacite_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the islandora_rdm_datacite module.
case 'help.page.islandora_rdm_datacite':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('DataCite API and services for producing DataCite data formats.') . '</p>';
return $output;
default:
}
}
/**
* Implementation of hook_node_update().
* Register the identifier with Datacite as 'Archived' if the node transitions away from 'Published'..
* This has to be separate from the presave hook because:
* 1. You can't update the node in this hook
* 2. The moderation state chagne is not available in the presave hook.
*
* @TODO: Replace this code if this is committed to core: https://www.drupal.org/project/drupal/issues/2873287
*
* @param \Drupal\Core\Entity\EntityInterface $entity
*/
function islandora_rdm_datacite_node_update(EntityInterface $entity) {
if ($entity->bundle() !== 'islandora_rdm_dataset') {
return;
}
$new_moderation_state = _islandora_rdm_datacite_get_entity_moderation_state($entity);
if (!empty($entity->original)) {
$original_moderation_state = _islandora_rdm_datacite_get_entity_moderation_state($entity->original);
}
else {
return;
}
$workflow_transition = rtrim($original_moderation_state . '-->' . $new_moderation_state);
switch ($workflow_transition) {
case 'published-->archived':
case 'archived-->archived':
$utils = \Drupal::service('islandora.utils');
// Execute delete reactions.
$utils->executeNodeReactions('\Drupal\islandora\Plugin\ContextReaction\DeleteReaction', $entity);
break;
}
return FALSE;
}
/**
* Helper function to get a node's moderation state string.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to get the moderation state from.
* @return false|mixed
* The moderation state string or FALSE if not found.
*/
function _islandora_rdm_datacite_get_entity_moderation_state(EntityInterface $entity) {
$current_entity_lang = $entity->get('langcode')->value;
$translated_entity = $entity->getTranslation($current_entity_lang);
if ($moderation_state_field = $translated_entity->get('moderation_state')
->first()) {
return $moderation_state_field->getValue()['value'];
}
return FALSE;
}