5 * Hooks provided by the Entity Embed module.
14 * Alter the Entity Embed Display plugin definitions.
17 * An associative array containing the plugin definitions keyed by plugin ID.
19 function hook_entity_embed_display_plugins_alter(array &$info) {
24 * Alter the Entity Embed Display plugin definitions for a given context.
26 * Usually used to remove certain Entity Embed Display plugins for specific
29 * @param array &$definitions
30 * Remove options from this list if they should not be available for the given
32 * @param array $contexts
33 * The provided context, typically an entity.
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'])) {
40 $entity = $contexts['entity'];
42 // For video and audio files, limit the available options to the media player.
43 if ($entity instanceof \Drupal\file\FileInterface && in_array($entity->bundle(), ['audio', 'video'])) {
44 $definitions = array_intersect_key($definitions, array_flip(['file:jwplayer_formatter']));
47 // For images, use the image formatter.
48 if ($entity instanceof \Drupal\file\FileInterface && in_array($entity->bundle(), ['image'])) {
49 $definitions = array_intersect_key($definitions, array_flip(['image:image']));
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']));
59 * Alter the context of an embedded entity before it is rendered.
61 * @param array &$context
63 * @param \Drupal\Core\Entity\EntityInterface $entity
66 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;
75 * Alter the context of an particular embedded entity type before it is rendered.
77 * @param array &$context
79 * @param \Drupal\Core\Entity\EntityInterface $entity
82 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;
91 * Alter the results of an embedded entity build array.
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.
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
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']);
112 * Alter the results of the particular embedded entity type build array.
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
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']);
129 * @} End of "addtogroup hooks".