diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 45d812a..929df64 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -1047,6 +1047,10 @@ protected function getDisplayModeOptionsByBundle($display_type, $entity_type_id, // Load all the entity's display modes. $display_modes = $this->getDisplayModesByEntityType($display_type, $entity_type_id); + // Set it as a list and always include our default view mode. + foreach ($display_modes as $display_mode_id => $display_mode) { + $display_mode_options[$display_mode_id] = $display_mode['label']; + } // Get the list of available entity displays for the current bundle. $ids = $this->configFactory->listAll($config_prefix . '.' . $entity_type_id . '.' . $bundle); @@ -1056,22 +1060,22 @@ protected function getDisplayModeOptionsByBundle($display_type, $entity_type_id, // Generate the display options array. We don't need to load the displays // if we don't care about the status. - if ($include_disabled) { - foreach ($display_modes as $display_mode) { - list(, $id) = explode('.', $display_mode['id']); - $display_mode_options[$id] = ($id == 'default') ? t('Default') : $display_mode['label']; - } - } - else { + if (!$include_disabled) { $entity_displays = entity_load_multiple($display_type_entity_name, $load_ids); foreach ($entity_displays as $display) { - if ($display->status() || $include_disabled || $display->id() == 'default') { + // Unset the display mode from the list if it is disabled. + if (!$display->status()) { $display_mode_name = $display->get('mode'); - $display_mode_options[$display_mode_name] = ($display_mode_name == 'default') ? t('Default') : $display_modes[$display_mode_name]['label']; + unset($display_mode_options[$display_mode_name]); } } } + // Add the default mode if we have more than 1 option. + if (count($display_mode_options) > 1) { + array_unshift($display_mode_options, array('default' => t('Default'))); + } + return $display_mode_options; }