function EntityDisplayRepository::getViewDisplay
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/EntityDisplayRepository.php \Drupal\Core\Entity\EntityDisplayRepository::getViewDisplay()
- 8.9.x core/lib/Drupal/Core/Entity/EntityDisplayRepository.php \Drupal\Core\Entity\EntityDisplayRepository::getViewDisplay()
- 11.x core/lib/Drupal/Core/Entity/EntityDisplayRepository.php \Drupal\Core\Entity\EntityDisplayRepository::getViewDisplay()
File
-
core/
lib/ Drupal/ Core/ Entity/ EntityDisplayRepository.php, line 249
Class
- EntityDisplayRepository
- Provides a repository for entity display objects (view modes and form modes).
Namespace
Drupal\Core\EntityCode
public function getViewDisplay($entity_type, $bundle, $view_mode = self::DEFAULT_DISPLAY_MODE) {
$storage = $this->entityTypeManager
->getStorage('entity_view_display');
// Try loading the display from configuration; if not found, create a fresh
// display object. We do not preemptively create new entity_view_display
// configuration entries for each existing entity type and bundle whenever a
// new view mode becomes available. Instead, configuration entries are only
// created when a display object is explicitly configured and saved.
$entity_view_display = $storage->load($entity_type . '.' . $bundle . '.' . $view_mode);
if (!$entity_view_display) {
$entity_view_display = $storage->create([
'targetEntityType' => $entity_type,
'bundle' => $bundle,
'mode' => $view_mode,
'status' => TRUE,
]);
}
return $entity_view_display;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.