1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Helper module for the Entity Embed tests. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
use Drupal\Core\Entity\EntityInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Implements hook_theme(). |
12
|
|
|
*/ |
13
|
|
|
function entity_embed_test_theme($existing, $type, $theme, $path) { |
|
|
|
|
14
|
|
|
$items['entity_embed_twig_test'] = array( |
|
|
|
|
15
|
|
|
'template' => 'entity_embed_twig_test', |
16
|
|
|
'variables' => array( |
17
|
|
|
'entity_type' => '', |
18
|
|
|
'id' => '', |
19
|
|
|
'display_plugin' => 'default', |
20
|
|
|
'display_settings' => array(), |
21
|
|
|
), |
22
|
|
|
); |
23
|
|
|
return $items; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Implements hook_entity_embed_display_plugins_alter(). |
29
|
|
|
*/ |
30
|
|
|
function entity_embed_test_entity_embed_display_plugins_alter(&$info) { |
31
|
|
|
// Allow tests to enable or disable this hook. |
32
|
|
|
if (!\Drupal::state()->get('entity_embed_test_entity_embed_display_plugins_alter', FALSE)) { |
33
|
|
|
return; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
// Prefix each plugin name with 'testing_hook:'. |
37
|
|
|
$new_info = array(); |
38
|
|
|
foreach ($info as $key => $value) { |
39
|
|
|
$new_key = "testing_hook:" . $key; |
40
|
|
|
$new_info[$new_key] = $info[$key]; |
41
|
|
|
unset($info[$key]); |
42
|
|
|
} |
43
|
|
|
$info = $new_info; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Implements hook_entity_embed_context_alter(). |
48
|
|
|
*/ |
49
|
|
|
function entity_embed_test_entity_embed_context_alter(array &$context, EntityInterface $entity) { |
50
|
|
|
// Allow tests to enable or disable this hook. |
51
|
|
|
if (!\Drupal::state()->get('entity_embed_test_entity_embed_context_alter', FALSE)) { |
52
|
|
|
return; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// Force to use 'Label' plugin. |
56
|
|
|
$context['data-entity-embed-display'] = 'entity_reference:entity_reference_label'; |
57
|
|
|
$context['data-entity-embed-settings'] = array('link' => 1); |
58
|
|
|
|
59
|
|
|
// Set title of the entity. |
60
|
|
|
$entity->setTitle("Title set by hook_entity_embed_context_alter"); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Implements hook_entity_embed_alter(). |
65
|
|
|
*/ |
66
|
|
|
function entity_embed_test_entity_embed_alter(array &$build, EntityInterface $entity, array $context) { |
|
|
|
|
67
|
|
|
// Allow tests to enable or disable this hook. |
68
|
|
|
if (!\Drupal::state()->get('entity_embed_test_entity_embed_alter', FALSE)) { |
69
|
|
|
return; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
// Set title of the 'node' entity. |
73
|
|
|
$node = $build['#node']; |
74
|
|
|
$node->setTitle("Title set by hook_entity_embed_alter"); |
75
|
|
|
} |
76
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.