function EntityDisplayRepository::getAllDisplayModesByEntityType

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityDisplayRepository.php \Drupal\Core\Entity\EntityDisplayRepository::getAllDisplayModesByEntityType()
  2. 8.9.x core/lib/Drupal/Core/Entity/EntityDisplayRepository.php \Drupal\Core\Entity\EntityDisplayRepository::getAllDisplayModesByEntityType()
  3. 10 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) {
                [
                    $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];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.