EntityDisplayRepository::getAllDisplayModesByEntityType

protected EntityDisplayRepository::getAllDisplayModesByEntityType($display_type)

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.

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];
}
doc_Drupal
2016-10-29 09:05:52
Comments
Leave a Comment

Please login to continue.