DevelEntityTestHooks.php

Namespace

Drupal\devel_entity_test\Hook

File

tests/modules/devel_entity_test/src/Hook/DevelEntityTestHooks.php

View source
<?php

namespace Drupal\devel_entity_test\Hook;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Hook\Attribute\Hook;
use Drupal\Core\StringTranslation\StringTranslationTrait;

/**
 * Hook implementations for devel_entity_test.
 */
class DevelEntityTestHooks {
  use StringTranslationTrait;
  public function __construct(protected readonly EntityTypeManagerInterface $entityTypeManager) {
  }
  
  /**
   * Implements hook_entity_view_mode_info_alter().
   */
  public function entityViewModeInfoAlter(array &$view_modes) : void {
    $entity_info = $this->entityTypeManager
      ->getDefinitions();
    foreach ($entity_info as $entity_type => $info) {
      if ($info->getProvider() !== 'devel_entity_test_canonical') {
        continue;
      }
      if (isset($view_modes[$entity_type])) {
        continue;
      }
      $view_modes[$entity_type] = [
        'full' => [
          'label' => $this->t('Full object'),
          'status' => TRUE,
          'cache' => TRUE,
        ],
        'teaser' => [
          'label' => $this->t('Teaser'),
          'status' => TRUE,
          'cache' => TRUE,
        ],
      ];
    }
  }

}

Classes

Title Deprecated Summary
DevelEntityTestHooks Hook implementations for devel_entity_test.