This repository has been archived by the owner on Jan 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
entity_embed.api.php
130 lines (117 loc) · 3.9 KB
/
entity_embed.api.php
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
<?php
/**
* @file
* Hooks provided by the Entity Embed module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Alter the Entity Embed Display plugin definitions.
*
* @param array &$info
* An associative array containing the plugin definitions keyed by plugin ID.
*/
function hook_entity_embed_display_plugins_alter(array &$info) {
}
/**
* Alter the Entity Embed Display plugin definitions for a given context.
*
* Usually used to remove certain Entity Embed Display plugins for specific
* entities.
*
* @param array &$definitions
* Remove options from this list if they should not be available for the given
* context.
* @param array $contexts
* The provided context, typically an entity.
*/
function hook_entity_embed_display_plugins_for_context_alter(array &$definitions, array $contexts) {
// Do nothing if no entity is provided.
if (!isset($contexts['entity'])) {
return;
}
$entity = $contexts['entity'];
// For video and audio files, limit the available options to the media player.
if ($entity instanceof \Drupal\file\FileInterface && in_array($entity->bundle(), ['audio', 'video'])) {
$definitions = array_intersect_key($definitions, array_flip(['file:jwplayer_formatter']));
}
// For images, use the image formatter.
if ($entity instanceof \Drupal\file\FileInterface && in_array($entity->bundle(), ['image'])) {
$definitions = array_intersect_key($definitions, array_flip(['image:image']));
}
// For nodes, use the default option.
if ($entity instanceof \Drupal\node\NodeInterface) {
$definitions = array_intersect_key($definitions, array_flip(['entity_reference:entity_reference_entity_view']));
}
}
/**
* Alter the context of an embedded entity before it is rendered.
*
* @param array &$context
* The context array.
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity object.
*/
function hook_entity_embed_context_alter(array &$context, \Drupal\Core\Entity\EntityInterface $entity) {
if (isset($context['overrides']) && is_array($context['overrides'])) {
foreach ($context['overrides'] as $key => $value) {
$entity->key = $value;
}
}
}
/**
* Alter the context of an particular embedded entity type before it is rendered.
*
* @param array &$context
* The context array.
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity object.
*/
function hook_ENTITY_TYPE_embed_context_alter(array &$context, \Drupal\Core\Entity\EntityInterface $entity) {
if (isset($context['overrides']) && is_array($context['overrides'])) {
foreach ($context['overrides'] as $key => $value) {
$entity->key = $value;
}
}
}
/**
* Alter the results of an embedded entity build array.
*
* This hook is called after the content has been assembled in a structured
* array and may be used for doing processing which requires that the complete
* block content structure has been built.
*
* @param array &$build
* A renderable array representing the embedded entity content.
* @param \Drupal\Core\Entity\EntityInterface $entity
* The embedded entity object.
* @param array $context
* The context array.
*/
function hook_entity_embed_alter(array &$build, \Drupal\Core\Entity\EntityInterface $entity, array &$context) {
// Remove the contextual links.
if (isset($build['#contextual_links'])) {
unset($build['#contextual_links']);
}
}
/**
* Alter the results of the particular embedded entity type build array.
*
* @param array &$build
* A renderable array representing the embedded entity content.
* @param \Drupal\Core\Entity\EntityInterface $entity
* The embedded entity object.
* @param array $context
* The context array.
*/
function hook_ENTITY_TYPE_embed_alter(array &$build, \Drupal\Core\Entity\EntityInterface $entity, array &$context) {
// Remove the contextual links.
if (isset($build['#contextual_links'])) {
unset($build['#contextual_links']);
}
}
/**
* @} End of "addtogroup hooks".
*/