protected function EntityDisplayRepository::getDisplayModeOptionsByBundle in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Entity/EntityDisplayRepository.php \Drupal\Core\Entity\EntityDisplayRepository::getDisplayModeOptionsByBundle()
- 10 core/lib/Drupal/Core/Entity/EntityDisplayRepository.php \Drupal\Core\Entity\EntityDisplayRepository::getDisplayModeOptionsByBundle()
Returns an array of enabled display mode options by bundle.
Parameters
$display_type: The display type to be retrieved. It can be "view_mode" or "form_mode".
string $entity_type_id: The entity type whose display mode options should be returned.
string $bundle: The name of the bundle.
Return value
array An array of display mode labels, keyed by the display mode ID.
2 calls to EntityDisplayRepository::getDisplayModeOptionsByBundle()
- EntityDisplayRepository::getFormModeOptionsByBundle in core/
lib/ Drupal/ Core/ Entity/ EntityDisplayRepository.php - Returns an array of enabled form mode options by bundle.
- EntityDisplayRepository::getViewModeOptionsByBundle in core/
lib/ Drupal/ Core/ Entity/ EntityDisplayRepository.php - Returns an array of enabled view mode options by bundle.
File
- core/
lib/ Drupal/ Core/ Entity/ EntityDisplayRepository.php, line 210
Class
- EntityDisplayRepository
- Provides a repository for entity display objects (view modes and form modes).
Namespace
Drupal\Core\EntityCode
protected function getDisplayModeOptionsByBundle($display_type, $entity_type_id, $bundle) {
// Collect all the entity's display modes.
$options = $this
->getDisplayModeOptions($display_type, $entity_type_id);
// Filter out modes for which the entity display is disabled
// (or non-existent).
$load_ids = [];
// Get the list of available entity displays for the current bundle.
foreach (array_keys($options) as $mode) {
$load_ids[] = $entity_type_id . '.' . $bundle . '.' . $mode;
}
// Load the corresponding displays.
$displays = $this->entityTypeManager
->getStorage($display_type == 'form_mode' ? 'entity_form_display' : 'entity_view_display')
->loadMultiple($load_ids);
// Unset the display modes that are not active or do not exist.
foreach (array_keys($options) as $mode) {
$display_id = $entity_type_id . '.' . $bundle . '.' . $mode;
if (!isset($displays[$display_id]) || !$displays[$display_id]
->status()) {
unset($options[$mode]);
}
}
return $options;
}