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;
class DevelEntityTestHooks {
use StringTranslationTrait;
public function __construct(protected readonly EntityTypeManagerInterface $entityTypeManager) {
}
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