class EntityTypeInfo in View Modes Display 8.2
Manipulates entity type information.
This class contains primarily bridged hooks for compile-time or cache-clear-time hooks. Runtime hooks should be placed in EntityOperations.
Hierarchy
- class \Drupal\view_modes_display\EntityTypeInfo implements ContainerInjectionInterface uses StringTranslationTrait
 
Expanded class hierarchy of EntityTypeInfo
1 file declares its use of EntityTypeInfo
File
- src/
EntityTypeInfo.php, line 18  
Namespace
Drupal\view_modes_displayView source
class EntityTypeInfo implements ContainerInjectionInterface {
  use StringTranslationTrait;
  /**
   * The current user.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $currentUser;
  /**
   * EntityDisplayRepository.
   *
   * @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
   */
  protected $entityDisplayRepository;
  /**
   * EntityTypeInfo constructor.
   *
   * @param \Drupal\Core\Session\AccountInterface $current_user
   *   Current user.
   */
  public function __construct(AccountInterface $current_user, EntityDisplayRepositoryInterface $entityDisplayRepository) {
    $this->currentUser = $current_user;
    $this->entityDisplayRepository = $entityDisplayRepository;
  }
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('current_user'), $container
      ->get('entity_display.repository'));
  }
  /**
   * Adds preview links to appropriate entity types.
   *
   * This is an alter hook bridge.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface[] $entity_types
   *   The master entity type list to alter.
   *
   * @see hook_entity_type_alter()
   */
  public function entityTypeAlter(array &$entity_types) {
    foreach ($entity_types as $entity_type_id => $entity_type) {
      if ($viewModes = $this->entityDisplayRepository
        ->getViewModes($entity_type_id)) {
        $entity_type
          ->setLinkTemplate('vmd-preview-list', "/{$entity_type_id}/{{$entity_type_id}}/view-mode/preview/list");
        $entity_type
          ->setLinkTemplate('vmd-preview-list', "/{$entity_type_id}/{{$entity_type_id}}/view-mode/preview/{view_mode}");
      }
    }
  }
  /**
   * Adds preview operations on entity that supports it.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The entity on which to define an operation.
   *
   * @return array
   *   An array of operation definitions.
   *
   * @see hook_entity_operation()
   */
  public function entityOperation(EntityInterface $entity) {
    $operations = [];
    if ($this->currentUser
      ->hasPermission('preview view modes')) {
      if ($entity
        ->hasLinkTemplate('vmd-preview-list')) {
        $operations['view-mode-display'] = [
          'title' => $this
            ->t('Preview'),
          'weight' => 100,
          'url' => $entity
            ->toUrl('vmd-preview-list'),
        ];
      }
    }
    return $operations;
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            EntityTypeInfo:: | 
                  protected | property | The current user. | |
| 
            EntityTypeInfo:: | 
                  protected | property | EntityDisplayRepository. | |
| 
            EntityTypeInfo:: | 
                  public static | function | 
            Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: | 
                  |
| 
            EntityTypeInfo:: | 
                  public | function | Adds preview operations on entity that supports it. | |
| 
            EntityTypeInfo:: | 
                  public | function | Adds preview links to appropriate entity types. | |
| 
            EntityTypeInfo:: | 
                  public | function | EntityTypeInfo constructor. | |
| 
            StringTranslationTrait:: | 
                  protected | property | The string translation service. | 1 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Formats a string containing a count of items. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Returns the number of plurals supported by a given language. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Gets the string translation service. | |
| 
            StringTranslationTrait:: | 
                  public | function | Sets the string translation service to use. | 2 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Translates a string to the current language or to a given language. |