'entity_embed_twig_test', 'variables' => array( 'entity_type' => '', 'id' => '', 'display_plugin' => 'default', 'display_settings' => array(), ), ); return $items; } /** * Implements hook_entity_embed_display_plugins_alter(). */ function entity_embed_test_entity_embed_display_plugins_alter(&$info) { // Allow tests to enable or disable this hook. if (!\Drupal::state()->get('entity_embed_test_entity_embed_display_plugins_alter', FALSE)) { return; } // Prefix each plugin name with 'testing_hook:'. $new_info = array(); foreach ($info as $key => $value) { $new_key = "testing_hook:" . $key; $new_info[$new_key] = $info[$key]; unset($info[$key]); } $info = $new_info; } /** * Implements hook_entity_embed_context_alter(). */ function entity_embed_test_entity_embed_context_alter(array &$context, EntityInterface $entity) { // Allow tests to enable or disable this hook. if (!\Drupal::state()->get('entity_embed_test_entity_embed_context_alter', FALSE)) { return; } // Force to use 'Label' plugin. $context['data-entity-embed-display'] = 'entity_reference:entity_reference_label'; $context['data-entity-embed-display-settings'] = array('link' => 1); // Set title of the entity. $entity->setTitle("Title set by hook_entity_embed_context_alter"); } /** * Implements hook_entity_embed_alter(). */ function entity_embed_test_entity_embed_alter(array &$build, EntityInterface $entity, array $context) { // Allow tests to enable or disable this hook. if (!\Drupal::state()->get('entity_embed_test_entity_embed_alter', FALSE)) { return; } // Set title of the 'node' entity. $entity->setTitle("Title set by hook_entity_embed_alter"); } /** * Implements hook_entity_access(). */ function entity_embed_test_entity_access(EntityInterface $entity, $operation, AccountInterface $account) { if ($entity->label() == 'Embed Test Node') { return AccessResult::neutral()->addCacheTags(['foo:' . $entity->id()]); } }