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.module
66 lines (60 loc) · 1.99 KB
/
entity_embed.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
<?php
/**
* @file
* Framework for allowing entities to be embedded using CKEditor plugin and text
* format.
*/
/**
* Implements hook_theme().
*/
function entity_embed_theme() {
return [
'entity_embed_container' => [
'render element' => 'element',
],
];
}
/**
* Prepares variables for entity embed container templates.
*
* Default template: entity-embed-container.html.twig.
*
* @param array $variables
* An associative array containing:
* - element: An associative array containing the properties of the element.
* Properties used: #attributes, #children.
*/
function template_preprocess_entity_embed_container(&$variables) {
$variables['element'] += ['#attributes' => []];
$variables['attributes'] = $variables['element']['#attributes'];
$variables['children'] = $variables['element']['#children'];
}
/**
* Implements hook_entity_embed_display_plugins_alter() on behalf of file.module.
*/
function file_entity_embed_display_plugins_alter(array &$plugins) {
// The RSS enclosure field formatter is not usable for Entity Embed.
unset($plugins['file:file_rss_enclosure']);
}
/**
* Implements hook_entity_embed_display_plugins_alter() on behalf of taxonomy.module.
*/
function taxonomy_entity_embed_display_plugins_alter(array &$plugins) {
// The RSS category field formatter is not usable for Entity Embed.
unset($plugins['entity_reference:entity_reference_rss_category']);
}
/**
* Implements hook_entity_embed_display_plugins_for_context_alter().
*
* The 'Rendered entity' formatter can not be used for files unless the
* file_entity module is available.
*
* @see https://www.drupal.org/node/2468387
*
* @todo Remove when https://www.drupal.org/node/2567919 is fixed in core.
*/
function entity_embed_entity_embed_display_plugins_for_context_alter(array &$definitions, array $context) {
if ($context['entity_type'] === 'file' && !\Drupal::moduleHandler()->moduleExists('file_entity')) {
unset($definitions['entity_reference:entity_reference_entity_view']);
}
}