-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentity_attributes.module
136 lines (109 loc) · 4.37 KB
/
entity_attributes.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
<?php
/**
* Render entity attributes to html.
*/
function entity_attributes_html(Drupal\Core\Entity\Entity $entity)
{
$entityAttributesHelper = new \Drupal\entity_attributes\Helper\EntityAttributesHelper();
}
/**
* Implements hook_entity_view().
*/
function entity_attributes_entity_view(
array &$build,
\Drupal\Core\Entity\EntityInterface $entity,
\Drupal\Core\Entity\Display\EntityViewDisplayInterface $display,
$view_mode
)
{
$entityAttributesHelper = new \Drupal\entity_attributes\Helper\EntityAttributesHelper();
$entityAttributes = $entityAttributesHelper->getEntityAttributes($entity);
if (!empty($entityAttributes)) {
$build['#entity_attributes'] = $entityAttributes;
}
}
/**
* Implements hook_preprocess().
*/
function entity_attributes_preprocess(&$variables, $hook)
{
$entityAttributes = [];
$entityAttributesHelper = new \Drupal\entity_attributes\Helper\EntityAttributesHelper();
if (isset($variables['elements']['#entity_attributes'])) {
$entityAttributes = $variables['elements']['#entity_attributes'];
}
if (isset($variables['elements']['content']['#entity_attributes'])) {
$entityAttributes = $variables['elements']['content']['#entity_attributes'];
}
if ($hook == 'ds_entity_view' && isset($variables['content']['#entity'])) {
$entityAttributes = $entityAttributesHelper->getEntityAttributes($variables['content']['#entity']);
}
if (!empty($entityAttributes)) {
if (!isset($variables['attributes'])) {
$variables['attributes'] = [];
}
$variables['attributes'] = array_merge_recursive($variables['attributes'], $entityAttributes);
}
}
/**
* Implements hook_ds_pre_render_alter().
*/
function entity_attributes_ds_pre_render_alter(array &$layout_render_array, array $context, array &$variables)
{
$entity = $context['entity'];
$entityAttributesHelper = new \Drupal\entity_attributes\Helper\EntityAttributesHelper();
$entityAttributes = $entityAttributesHelper->getEntityAttributes($entity);
if (!empty($entityAttributes)) {
$variables['attributes'] = array_merge_recursive($variables['attributes'], $entityAttributes);
}
}
function entity_attributes_preprocess_field__ds_field_expert(&$variables)
{
$entity = $variables['element']['#object'];
$entityAttributesHelper = new \Drupal\entity_attributes\Helper\EntityAttributesHelper();
$entityAttributes = $entityAttributesHelper->getEntityAttributes($entity);
$attributeMapping = [
'lbw-at' => 'label_attributes',
'ow-at' => 'wrapper_attributes',
'fis-at' => 'field_wrapper_attributes',
'fi-at' => 'field_item_wrapper_attributes',
];
foreach ($attributeMapping as $settingName => $attributeField) {
if (strpos($variables['settings'][$settingName], '{{entity_attributes}}') !== false) {
$variables['settings'][$settingName] = str_replace(
'{{entity_attributes}}',
'',
$variables['settings'][$settingName]
);
if (!empty($entityAttributes)) {
$variables[$attributeField]->mergeAttributes(new \Drupal\ds\DsAttribute($entityAttributes));
}
}
}
}
function entity_attributes_field_group_pre_render_alter(&$element, $group, $rendering_object)
{
if (!isset($rendering_object['#entity'])) {
return null;
}
$entity = $rendering_object['#entity'];
$entityAttributesHelper = new \Drupal\entity_attributes\Helper\EntityAttributesHelper();
$entityAttributes = $entityAttributesHelper->getEntityAttributes($entity);
if ($group->format_type == 'html_element' && !empty($group->format_settings['attributes'])) {
if ($element['#attributes'] && strpos('{{entity_attributes}}', $group->format_settings['attributes']) !== false) {
$attributeArray = $entityAttributes;
$originalAttributes = $element['#attributes']->toArray();
$mergedAttributes = array_merge_recursive($attributeArray, $originalAttributes);
$element['#attributes'] = new \Drupal\Core\Template\Attribute($mergedAttributes);
}
}
}
/**
* Implements hook_editor_js_settings_alter()
* @param array $settings
*/
function sarco_site_editor_js_settings_alter(array &$settings) {
foreach ($settings['editor']['formats'] as $name => $value) {
$settings['editor']['formats'][$name]['editorSettings']['autoParagraph'] = FALSE;
}
}