Completed
Push — 8.x-1.x ( 63ce40...607254 )
by Janez
02:22
created

entity_embed.module::template_preprocess_entity_embed_container()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 4
c 1
b 1
f 0
nc 1
nop 1
dl 0
loc 5
rs 9.4285
1
<?php
2
3
/**
4
 * @file
5
 * Framework for allowing entities to be embedded using CKEditor plugin and text
6
 * format.
7
 */
8
9
/**
10
 * Implements hook_theme().
11
 */
12
function entity_embed_theme() {
13
  return [
14
    'entity_embed_container' => [
15
      'render element' => 'element',
16
    ],
17
  ];
18
}
19
20
/**
21
 * Prepares variables for entity embed container templates.
22
 *
23
 * Default template: entity-embed-container.html.twig.
24
 *
25
 * @param array $variables
26
 *   An associative array containing:
27
 *   - element: An associative array containing the properties of the element.
28
 *     Properties used: #attributes, #children.
29
 */
30
function template_preprocess_entity_embed_container(&$variables) {
31
  $variables['element'] += ['#attributes' => []];
32
  $variables['attributes'] = $variables['element']['#attributes'];
33
  $variables['children'] = $variables['element']['#children'];
34
}
35
36
/**
37
 * Implements hook_entity_embed_display_plugins_alter() on behalf of file.module.
38
 */
39
function file_entity_embed_display_plugins_alter(array &$plugins) {
40
  // The RSS enclosure field formatter is not usable for Entity Embed.
41
  unset($plugins['file:file_rss_enclosure']);
42
}
43
44
/**
45
 * Implements hook_entity_embed_display_plugins_alter() on behalf of taxonomy.module.
46
 */
47
function taxonomy_entity_embed_display_plugins_alter(array &$plugins) {
48
  // The RSS category field formatter is not usable for Entity Embed.
49
  unset($plugins['entity_reference:entity_reference_rss_category']);
50
}
51
52
/**
53
 * Implements hook_entity_embed_display_plugins_for_context_alter().
54
 *
55
 * The 'Rendered entity' formatter can not be used for files unless the
56
 * file_entity module is available.
57
 * @see https://www.drupal.org/node/2468387
58
 * @todo Remove when https://www.drupal.org/node/2567919 is fixed in core.
59
 */
60
function entity_embed_entity_embed_display_plugins_for_context_alter(array &$definitions, array $context) {
61
  if ($context['entity_type'] === 'file' && !\Drupal::moduleHandler()->moduleExists('file_entity')) {
62
    unset($definitions['entity_reference:entity_reference_entity_view']);
63
  }
64
}
65