-
Notifications
You must be signed in to change notification settings - Fork 0
/
larkm_integration.module
33 lines (28 loc) · 1.05 KB
/
larkm_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
<?php
/**
* @file
* larkm Integration module.
*/
use Drupal\node\NodeInterface;
/**
* Implements hook_ENTITY_TYPE_presave for Node entities.
*/
function larkm_integration_node_presave(NodeInterface $node) {
$config = \Drupal::config('larkm_integration.settings');
$ark_fieldname = $config->get('larkm_integration_ark_fieldname');
$larkm_hostname = $config->get('larkm_integration_larkm_hostname');
$naan = $config->get('larkm_integration_naan');
$shoulder = $config->get('larkm_integration_shoulder');
$ark_url = $larkm_hostname . '/ark:/' . $naan . '/' . $shoulder . $node->uuid();
$allowed_bundles = $config->get('larkm_integration_bundles');
if (in_array($node->bundle(), $allowed_bundles, TRUE) && $node->hasField($ark_fieldname)) {
$raw_field_values = $node->get($ark_fieldname)->getValue();
$field_values = [];
foreach ($raw_field_values as $raw_field_value) {
$field_values[] = $raw_field_value['value'];
}
if (!in_array($ark_url, $field_values)) {
$node->{$ark_fieldname}->appendItem($ark_url);
}
}
}