You are here

media_test_embed.module in Drupal 10

Helper module for the Media Embed text editor plugin tests.

File

core/modules/media/tests/modules/media_test_embed/media_test_embed.module
View source
<?php

/**
 * @file
 * Helper module for the Media Embed text editor plugin tests.
 */
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;

/**
 * Implements hook_entity_view_alter().
 */
function media_test_embed_entity_view_alter(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
  $build['#attributes']['data-media-embed-test-active-theme'] = \Drupal::theme()
    ->getActiveTheme()
    ->getName();
  $build['#attributes']['data-media-embed-test-view-mode'] = $display
    ->getMode();
}

/**
 * Implements hook_preprocess_HOOK().
 */
function media_test_embed_preprocess_media_embed_error(&$variables) {
  $variables['attributes']['class'][] = 'this-error-message-is-themeable';
}

/**
 * Implements hook_entity_access().
 */
function media_test_embed_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
  return AccessResult::neutral()
    ->addCacheTags([
    '_media_test_embed_filter_access:' . $entity
      ->getEntityTypeId() . ':' . $entity
      ->id(),
  ]);
}