5 * Helper module for the Entity Embed tests.
8 use Drupal\Core\Access\AccessResult;
9 use Drupal\Core\Entity\EntityInterface;
10 use Drupal\Core\Session\AccountInterface;
13 * Implements hook_theme().
15 function entity_embed_test_theme($existing, $type, $theme, $path) {
16 $items['entity_embed_twig_test'] = array(
17 'template' => 'entity_embed_twig_test',
21 'display_plugin' => 'default',
22 'display_settings' => array(),
29 * Implements hook_entity_embed_display_plugins_alter().
31 function entity_embed_test_entity_embed_display_plugins_alter(&$info) {
32 // Allow tests to enable or disable this hook.
33 if (!\Drupal::state()->get('entity_embed_test_entity_embed_display_plugins_alter', FALSE)) {
37 // Prefix each plugin name with 'testing_hook:'.
39 foreach ($info as $key => $value) {
40 $new_key = "testing_hook:" . $key;
41 $new_info[$new_key] = $info[$key];
48 * Implements hook_entity_embed_context_alter().
50 function entity_embed_test_entity_embed_context_alter(array &$context, EntityInterface $entity) {
51 // Allow tests to enable or disable this hook.
52 if (!\Drupal::state()->get('entity_embed_test_entity_embed_context_alter', FALSE)) {
56 // Force to use 'Label' plugin.
57 $context['data-entity-embed-display'] = 'entity_reference:entity_reference_label';
58 $context['data-entity-embed-display-settings'] = array('link' => 1);
60 // Set title of the entity.
61 $entity->setTitle("Title set by hook_entity_embed_context_alter");
65 * Implements hook_entity_embed_alter().
67 function entity_embed_test_entity_embed_alter(array &$build, EntityInterface $entity, array $context) {
68 // Allow tests to enable or disable this hook.
69 if (!\Drupal::state()->get('entity_embed_test_entity_embed_alter', FALSE)) {
73 // Set title of the 'node' entity.
74 $entity->setTitle("Title set by hook_entity_embed_alter");
78 * Implements hook_entity_access().
80 function entity_embed_test_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
81 if ($entity->label() == 'Embed Test Node') {
82 return AccessResult::neutral()->addCacheTags(['foo:' . $entity->id()]);