You are here

function entity_embed_test_entity_embed_context_alter in Entity Embed 8

Same name and namespace in other branches
  1. 7.3 tests/entity_embed_test.module \entity_embed_test_entity_embed_context_alter()
  2. 7 tests/entity_embed_test.module \entity_embed_test_entity_embed_context_alter()
  3. 7.2 tests/entity_embed_test.module \entity_embed_test_entity_embed_context_alter()

Implements hook_entity_embed_context_alter().

1 string reference to 'entity_embed_test_entity_embed_context_alter'
EntityEmbedHooksTest::testEntityEmbedHooks in tests/src/Functional/EntityEmbedHooksTest.php
Tests the hooks provided by entity_embed module.

File

tests/modules/entity_embed_test/entity_embed_test.module, line 51
Helper module for the Entity Embed tests.

Code

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'] = [
    'link' => 1,
  ];

  // Set title of the entity.
  $entity
    ->setTitle("Title set by hook_entity_embed_context_alter");
}