1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Hooks provided by the Entity Embed module. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @addtogroup hooks |
10
|
|
|
* @{ |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Alter the Entity Embed Display plugin definitions. |
15
|
|
|
* |
16
|
|
|
* @param array &$info |
17
|
|
|
* An associative array containing the plugin definitions keyed by plugin ID. |
18
|
|
|
*/ |
19
|
|
|
function hook_entity_embed_display_plugins_alter(array &$info) { |
|
|
|
|
20
|
|
|
|
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Alter the Entity Embed Display plugin definitions for a given context. |
25
|
|
|
* |
26
|
|
|
* Usually used to remove certain Entity Embed Display plugins for specific |
27
|
|
|
* entities. |
28
|
|
|
* |
29
|
|
|
* @param array &$definitions |
30
|
|
|
* Remove options from this list if they should not be available for the given |
31
|
|
|
* context. |
32
|
|
|
* @param array $contexts |
33
|
|
|
* The provided context, typically an entity. |
34
|
|
|
*/ |
35
|
|
|
function hook_entity_embed_display_plugins_for_context_alter(array &$definitions, array $contexts) { |
36
|
|
|
// Do nothing if no entity is provided. |
37
|
|
|
if (!isset($contexts['entity'])) { |
38
|
|
|
return; |
39
|
|
|
} |
40
|
|
|
$entity = $contexts['entity']; |
41
|
|
|
|
42
|
|
|
// For video and audio files, limit the available options to the media player. |
43
|
|
View Code Duplication |
if ($entity instanceof \Drupal\file\FileInterface && in_array($entity->bundle(), ['audio', 'video'])) { |
|
|
|
|
44
|
|
|
$definitions = array_intersect_key($definitions, array_flip(['file:jwplayer_formatter'])); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// For images, use the image formatter. |
48
|
|
View Code Duplication |
if ($entity instanceof \Drupal\file\FileInterface && in_array($entity->bundle(), ['image'])) { |
|
|
|
|
49
|
|
|
$definitions = array_intersect_key($definitions, array_flip(['image:image'])); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
// For nodes, use the default option. |
53
|
|
|
if ($entity instanceof \Drupal\node\NodeInterface) { |
|
|
|
|
54
|
|
|
$definitions = array_intersect_key($definitions, array_flip(['entity_reference:entity_reference_entity_view'])); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Alter the context of an embedded entity before it is rendered. |
60
|
|
|
* |
61
|
|
|
* @param array &$context |
62
|
|
|
* The context array. |
63
|
|
|
* @param \Drupal\Core\Entity\EntityInterface $entity |
64
|
|
|
* The entity object. |
65
|
|
|
*/ |
66
|
|
View Code Duplication |
function hook_entity_embed_context_alter(array &$context, \Drupal\Core\Entity\EntityInterface $entity) { |
|
|
|
|
67
|
|
|
if (isset($context['overrides']) && is_array($context['overrides'])) { |
68
|
|
|
foreach ($context['overrides'] as $key => $value) { |
69
|
|
|
$entity->key = $value; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Alter the context of an particular embedded entity type before it is rendered. |
76
|
|
|
* |
77
|
|
|
* @param array &$context |
78
|
|
|
* The context array. |
79
|
|
|
* @param \Drupal\Core\Entity\EntityInterface $entity |
80
|
|
|
* The entity object. |
81
|
|
|
*/ |
82
|
|
View Code Duplication |
function hook_ENTITY_TYPE_embed_context_alter(array &$context, \Drupal\Core\Entity\EntityInterface $entity) { |
|
|
|
|
83
|
|
|
if (isset($context['overrides']) && is_array($context['overrides'])) { |
84
|
|
|
foreach ($context['overrides'] as $key => $value) { |
85
|
|
|
$entity->key = $value; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Alter the results of an embedded entity build array. |
92
|
|
|
* |
93
|
|
|
* This hook is called after the content has been assembled in a structured |
94
|
|
|
* array and may be used for doing processing which requires that the complete |
95
|
|
|
* block content structure has been built. |
96
|
|
|
* |
97
|
|
|
* @param array &$build |
98
|
|
|
* A renderable array representing the embedded entity content. |
99
|
|
|
* @param \Drupal\Core\Entity\EntityInterface $entity |
100
|
|
|
* The embedded entity object. |
101
|
|
|
* @param array $context |
102
|
|
|
* The context array. |
103
|
|
|
*/ |
104
|
|
|
function hook_entity_embed_alter(array &$build, \Drupal\Core\Entity\EntityInterface $entity, array &$context) { |
|
|
|
|
105
|
|
|
// Remove the contextual links. |
106
|
|
|
if (isset($build['#contextual_links'])) { |
107
|
|
|
unset($build['#contextual_links']); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Alter the results of the particular embedded entity type build array. |
113
|
|
|
* |
114
|
|
|
* @param array &$build |
115
|
|
|
* A renderable array representing the embedded entity content. |
116
|
|
|
* @param \Drupal\Core\Entity\EntityInterface $entity |
117
|
|
|
* The embedded entity object. |
118
|
|
|
* @param array $context |
119
|
|
|
* The context array. |
120
|
|
|
*/ |
121
|
|
|
function hook_ENTITY_TYPE_embed_alter(array &$build, \Drupal\Core\Entity\EntityInterface $entity, array &$context) { |
|
|
|
|
122
|
|
|
// Remove the contextual links. |
123
|
|
|
if (isset($build['#contextual_links'])) { |
124
|
|
|
unset($build['#contextual_links']); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @} End of "addtogroup hooks". |
130
|
|
|
*/ |
131
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.