You are here

protected function EntityDisplayRepository::getAllDisplayModesByEntityType in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityDisplayRepository.php \Drupal\Core\Entity\EntityDisplayRepository::getAllDisplayModesByEntityType()

Gets the entity display mode info for all entity types.

Parameters

string $display_type: The display type to be retrieved. It can be "view_mode" or "form_mode".

Return value

array The display mode info for all entity types.

3 calls to EntityDisplayRepository::getAllDisplayModesByEntityType()
EntityDisplayRepository::getAllFormModes in core/lib/Drupal/Core/Entity/EntityDisplayRepository.php
Gets the entity form mode info for all entity types.
EntityDisplayRepository::getAllViewModes in core/lib/Drupal/Core/Entity/EntityDisplayRepository.php
Gets the entity view mode info for all entity types.
EntityDisplayRepository::getDisplayModesByEntityType in core/lib/Drupal/Core/Entity/EntityDisplayRepository.php
Gets the entity display mode info for a specific entity type.

File

core/lib/Drupal/Core/Entity/EntityDisplayRepository.php, line 104

Class

EntityDisplayRepository
Provides a repository for entity display objects (view modes and form modes).

Namespace

Drupal\Core\Entity

Code

protected function getAllDisplayModesByEntityType($display_type) {
  if (!isset($this->displayModeInfo[$display_type])) {
    $key = 'entity_' . $display_type . '_info';
    $entity_type_id = 'entity_' . $display_type;
    $langcode = $this->languageManager
      ->getCurrentLanguage(LanguageInterface::TYPE_INTERFACE)
      ->getId();
    if ($cache = $this
      ->cacheGet("{$key}:{$langcode}")) {
      $this->displayModeInfo[$display_type] = $cache->data;
    }
    else {
      $this->displayModeInfo[$display_type] = [];
      foreach ($this->entityTypeManager
        ->getStorage($entity_type_id)
        ->loadMultiple() as $display_mode) {
        list($display_mode_entity_type, $display_mode_name) = explode('.', $display_mode
          ->id(), 2);
        $this->displayModeInfo[$display_type][$display_mode_entity_type][$display_mode_name] = $display_mode
          ->toArray();
      }
      $this->moduleHandler
        ->alter($key, $this->displayModeInfo[$display_type]);
      $this
        ->cacheSet("{$key}:{$langcode}", $this->displayModeInfo[$display_type], CacheBackendInterface::CACHE_PERMANENT, [
        'entity_types',
        'entity_field_info',
      ]);
    }
  }
  return $this->displayModeInfo[$display_type];
}