-
Notifications
You must be signed in to change notification settings - Fork 15
/
oe_content.module
138 lines (123 loc) · 4.66 KB
/
oe_content.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* @file
* The OpenEuropa Content module.
*/
declare(strict_types=1);
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\link\LinkItemInterface;
/**
* Implements hook_entity_base_field_info().
*/
function oe_content_entity_base_field_info(EntityTypeInterface $entity_type) {
$fields = [];
if ($entity_type->id() !== 'node') {
return $fields;
}
$fields['oe_content_short_title'] = BaseFieldDefinition::create('string')
->setLabel(t('Alternative title'))
->setDescription(t('Use this field to create an alternative title for use in the URL and in list views. If the page title is longer than 60 characters, you can add a shorter title here.'))
->setRequired(FALSE)
->setTranslatable(TRUE)
->setRevisionable(TRUE)
->setSetting('max_length', 255)
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => 0,
])
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE);
$fields['oe_content_navigation_title'] = BaseFieldDefinition::create('string')
->setLabel(t('Navigation title'))
->setDescription(t('When filled in, the navigation title will replace the page title in the breadcrumb, horizontal menu and navigation blocks.'))
->setRequired(FALSE)
->setTranslatable(TRUE)
->setRevisionable(TRUE)
->setSetting('max_length', 255)
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => 0,
])
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE);
$fields['oe_content_content_owner'] = BaseFieldDefinition::create('skos_concept_entity_reference')
->setLabel(t('Content owner'))
->setDescription(t('This is not the writer of the content, but the subject matter expert responsible for keeping this content up to date.'))
->setRequired(TRUE)
->setTranslatable(FALSE)
->setRevisionable(TRUE)
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setSettings([
'target_type' => 'skos_concept',
'handler_settings' => [
'concept_schemes' => [
'http://publications.europa.eu/resource/authority/corporate-body',
],
'field' => [
'field_name' => 'oe_content_content_owner',
'entity_type' => 'node',
'bundle' => NULL,
'concept_schemes' => [
'http://publications.europa.eu/resource/authority/corporate-body',
],
],
],
'default_value' => 0,
])
->setDisplayOptions('form', [
'type' => 'skos_concept_entity_reference_autocomplete',
'weight' => 0,
])
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE);
$fields['oe_content_legacy_link'] = BaseFieldDefinition::create('link')
->setLabel(t('Redirect link'))
->setDescription(t('Add a link to this field to automatically redirect the user to a different page. Use this to prevent duplication of content.'))
->setRequired(FALSE)
->setTranslatable(TRUE)
->setRevisionable(TRUE)
->setSettings([
'link_type' => LinkItemInterface::LINK_EXTERNAL,
'title' => DRUPAL_DISABLED,
])
->setDisplayOptions('form', [
'type' => 'link_default',
'weight' => 0,
])
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE);
return $fields;
}
/**
* Implements hook_locale_translation_projects_alter().
*/
function oe_content_locale_translation_projects_alter(&$projects) {
$projects['oe_content']['info']['interface translation server pattern'] = \Drupal::service('extension.list.module')->getPath('oe_content') . '/translations/%project-%language.po';
}
/**
* Implements hook_ENTITY_TYPE_prepare_form().
*/
function oe_content_node_prepare_form(EntityInterface $entity, $operation, FormStateInterface $form_state) {
/** @var \Drupal\node\NodeInterface $entity */
if ($entity->isNew() === FALSE) {
return;
}
if ($entity->hasField('oe_content_content_owner') === FALSE) {
return;
}
if (\Drupal::service('module_handler')->moduleExists('oe_corporate_site_info') === FALSE) {
return;
}
/** @var \Drupal\oe_corporate_site_info\SiteInformationInterface $site_information */
$site_information = \Drupal::service('oe_corporate_site_info.site_information');
if (!$site_information->hasDefaultContentOwners()) {
// No content owner(s) defined.
return;
}
$content_owners = $site_information->getDefaultContentOwners();
$entity->set('oe_content_content_owner', array_values($content_owners));
}