diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 2859b5963f37f2e15b3953a7a114c5bd2def2947..761e38671201a0be472721dee4245121e2eab524 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -14,7 +14,6 @@ * Resets the cached information about entity types. */ function entity_info_cache_clear() { - drupal_static_reset('entity_get_view_modes'); // Clear all languages. \Drupal::entityManager()->clearCachedDefinitions(); \Drupal::entityManager()->clearCachedFieldDefinitions(); @@ -83,77 +82,45 @@ function entity_invoke_bundle_hook($hook, $entity_type, $bundle, $bundle_new = N /** * Returns the entity form mode info. * - * @param string|null $entity_type + * @param string|null $entity_type_id * The entity type whose form mode info should be returned, or NULL for all * form mode info. Defaults to NULL. * * @return array * The form mode info for a specific entity type, or all entity types. + * + * @deprecated Use \Drupal::entityManager()->getFormModes() or + * \Drupal::entityManager()->getAllFormModes(). */ -function entity_get_form_modes($entity_type = NULL) { - $form_modes = &drupal_static(__FUNCTION__); - if (!$form_modes) { - $langcode = \Drupal::languageManager()->getCurrentLanguage()->id; - if ($cache = \Drupal::cache()->get("entity_form_mode_info:$langcode")) { - $form_modes = $cache->data; - } - else { - $form_modes = array(); - foreach (entity_load_multiple('form_mode') as $form_mode) { - list($form_mode_entity_type, $form_mode_name) = explode('.', $form_mode->id(), 2); - $form_modes[$form_mode_entity_type][$form_mode_name] = (array) $form_mode; - } - \Drupal::moduleHandler()->alter('entity_form_mode_info', $form_modes); - \Drupal::cache()->set("entity_form_mode_info:$langcode", $form_modes, Cache::PERMANENT, array('entity_types' => TRUE)); - } +function entity_get_form_modes($entity_type_id = NULL) { + if (isset($entity_type_id)) { + return \Drupal::entityManager()->getFormModes($entity_type_id); } - - if (empty($entity_type)) { - return $form_modes; - } - elseif (isset($form_modes[$entity_type])) { - return $form_modes[$entity_type]; + else { + return \Drupal::entityManager()->getAllFormModes(); } - - return array(); } /** * Returns the entity view mode info. * - * @param string|null $entity_type + * @param string|null $entity_type_id * The entity type whose view mode info should be returned, or NULL for all * view mode info. Defaults to NULL. * * @return array * The view mode info for a specific entity type, or all entity types. + * + * @deprecated Use \Drupal::entityManager()->getViewModes() or + * \Drupal::entityManager()->getAllViewModes(). */ -function entity_get_view_modes($entity_type = NULL) { - $view_modes = &drupal_static(__FUNCTION__); - if (!$view_modes) { - $langcode = \Drupal::languageManager()->getCurrentLanguage()->id; - if ($cache = \Drupal::cache()->get("entity_view_mode_info:$langcode")) { - $view_modes = $cache->data; - } - else { - $view_modes = array(); - foreach (entity_load_multiple('view_mode') as $view_mode) { - list($view_mode_entity_type, $view_mode_name) = explode('.', $view_mode->id(), 2); - $view_modes[$view_mode_entity_type][$view_mode_name] = (array) $view_mode; - } - \Drupal::moduleHandler()->alter('entity_view_mode_info', $view_modes); - \Drupal::cache()->set("entity_view_mode_info:$langcode", $view_modes, Cache::PERMANENT, array('entity_types' => TRUE)); - } +function entity_get_view_modes($entity_type_id = NULL) { + if (isset($entity_type_id)) { + return \Drupal::entityManager()->getViewModes($entity_type_id); } - - if (empty($entity_type)) { - return $view_modes; - } - elseif (isset($view_modes[$entity_type])) { - return $view_modes[$entity_type]; + else { + return \Drupal::entityManager()->getAllViewModes(); } - - return array(); } /** diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 00c9d73d53b87bcfdab16bff25de9bdbc533c08a..0e8e6b8a0c48ff9b612d1eb4d33f848c00a40c58 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -114,6 +114,13 @@ class EntityManager extends PluginManagerBase implements EntityManagerInterface */ protected $bundleInfo; + /** + * Static cache of display modes information. + * + * @var array + */ + protected $displayModeInfo = array(); + /** * Constructs a new Entity plugin manager. * @@ -155,6 +162,7 @@ public function clearCachedDefinitions() { parent::clearCachedDefinitions(); $this->bundleInfo = NULL; + $this->displayModeInfo = array(); } /** @@ -509,4 +517,123 @@ public function getTranslationFromContext(EntityInterface $entity, $langcode = N return $translation; } + /** + * {@inheritdoc} + */ + public function getAllViewModes() { + return $this->getAllDisplayModesByEntityType('view_mode'); + } + + /** + * {@inheritdoc} + */ + public function getViewModes($entity_type_id) { + return $this->getDisplayModesByEntityType('view_mode', $entity_type_id); + } + + /** + * {@inheritdoc} + */ + public function getAllFormModes() { + return $this->getAllDisplayModesByEntityType('form_mode'); + } + + /** + * {@inheritdoc} + */ + public function getFormModes($entity_type_id) { + return $this->getDisplayModesByEntityType('form_mode', $entity_type_id); + } + + /** + * Returns the entity display mode info for all entity types. + * + * @param string $display_type + * The display type to be retrieved. It can be "view_mode" or "form_mode". + * + * @return array + * The display mode info for all entity types. + */ + protected function getAllDisplayModesByEntityType($display_type) { + if (!isset($this->displayModeInfo[$display_type])) { + $key = 'entity_' . $display_type . '_info'; + $langcode = $this->languageManager->getCurrentLanguage(Language::TYPE_INTERFACE)->id; + if ($cache = $this->cache->get("$key:$langcode")) { + $this->displayModeInfo[$display_type] = $cache->data; + } + else { + $this->displayModeInfo[$display_type] = array(); + foreach ($this->getStorageController($display_type)->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] = (array) $display_mode; + } + $this->moduleHandler->alter($key, $this->displayModeInfo[$display_type]); + $this->cache->set("$key:$langcode", $this->displayModeInfo[$display_type], CacheBackendInterface::CACHE_PERMANENT, array('entity_types' => TRUE)); + } + } + + return $this->displayModeInfo[$display_type]; + } + + /** + * Returns the entity display mode info for a specific entity type. + * + * @param string $display_type + * The display type to be retrieved. It can be "view_mode" or "form_mode". + * @param string $entity_type_id + * The entity type whose display mode info should be returned. + * + * @return array + * The display mode info for a specific entity type. + */ + protected function getDisplayModesByEntityType($display_type, $entity_type_id) { + if (isset($this->displayModeInfo[$display_type][$entity_type_id])) { + return $this->displayModeInfo[$display_type][$entity_type_id]; + } + else { + $display_modes = $this->getAllDisplayModesByEntityType($display_type); + if (isset($display_modes[$entity_type_id])) { + return $display_modes[$entity_type_id]; + } + } + return array(); + } + + /** + * {@inheritdoc} + */ + public function getViewModeOptions($entity_type, $include_disabled = FALSE) { + return $this->getDisplayModeOptions('view_mode', $entity_type, $include_disabled); + } + + /** + * {@inheritdoc} + */ + public function getFormModeOptions($entity_type, $include_disabled = FALSE) { + return $this->getDisplayModeOptions('form_mode', $entity_type, $include_disabled); + } + + /** + * Returns an array of display mode options. + * + * @param string $display_type + * The display type to be retrieved. It can be "view_mode" or "form_mode". + * @param string $entity_type_id + * The entity type whose display mode options should be returned. + * @param bool $include_disabled + * Force to include disabled display modes. Defaults to FALSE. + * + * @return array + * An array of display mode labels, keyed by the display mode ID. + */ + protected function getDisplayModeOptions($display_type, $entity_type_id, $include_disabled = FALSE) { + $options = array('default' => t('Default')); + foreach ($this->getDisplayModesByEntityType($display_type, $entity_type_id) as $mode => $settings) { + if (!empty($settings['status']) || $include_disabled) { + $options[$mode] = $settings['label']; + } + } + return $options; + } + } diff --git a/core/lib/Drupal/Core/Entity/EntityManagerInterface.php b/core/lib/Drupal/Core/Entity/EntityManagerInterface.php index 9a65866e10a96598294cf5f28843fbc0595d216f..bb8e0d9cb4a70e4b295fec24752d1fac458a7d7e 100644 --- a/core/lib/Drupal/Core/Entity/EntityManagerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityManagerInterface.php @@ -235,4 +235,68 @@ public function getDefinition($entity_type_id, $exception_on_invalid = FALSE); */ public function getDefinitions(); + /** + * Returns the entity view mode info for all entity types. + * + * @return array + * The view mode info for all entity types. + */ + public function getAllViewModes(); + + /** + * Returns the entity view mode info for a specific entity type. + * + * @param string $entity_type_id + * The entity type whose view mode info should be returned. + * + * @return array + * The view mode info for a specific entity type. + */ + public function getViewModes($entity_type_id); + + /** + * Returns the entity form mode info for all entity types. + * + * @return array + * The form mode info for all entity types. + */ + public function getAllFormModes(); + + /** + * Returns the entity form mode info for a specific entity type. + * + * @param string $entity_type_id + * The entity type whose form mode info should be returned. + * + * @return array + * The form mode info for a specific entity type. + */ + public function getFormModes($entity_type_id); + + /** + * Returns an array of view mode options. + * + * @param string $entity_type_id + * The entity type whose view mode options should be returned. + * @param bool $include_disabled + * Force to include disabled view modes. Defaults to FALSE. + * + * @return array + * An array of view mode labels, keyed by the display mode ID. + */ + public function getViewModeOptions($entity_type_id, $include_disabled = FALSE); + + /** + * Returns an array of form mode options. + * + * @param string $entity_type_id + * The entity type whose form mode options should be returned. + * @param bool $include_disabled + * Force to include disabled form modes. Defaults to FALSE. + * + * @return array + * An array of form mode labels, keyed by the display mode ID. + */ + public function getFormModeOptions($entity_type_id, $include_disabled = FALSE); + } diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index 2e48eccb3dcadb7a0707c7e4cd1d055c7b6a9ef3..798fdef484db931ac0f7b99688378215ab9dc5cd 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -362,7 +362,7 @@ protected function isViewModeCacheable($view_mode) { // The 'default' is not an actual view mode. return TRUE; } - $view_modes_info = entity_get_view_modes($this->entityTypeId); + $view_modes_info = $this->entityManager->getViewModes($this->entityTypeId); return !empty($view_modes_info[$view_mode]['cache']); } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Block/CustomBlockBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Block/CustomBlockBlock.php index dab9b26e7c7dc82a933527fee741c99e08245dbe..e05089e325c99bf18aa5d3f2d71951a0524fd6ba 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Block/CustomBlockBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Block/CustomBlockBlock.php @@ -8,6 +8,8 @@ namespace Drupal\custom_block\Plugin\Block; use Drupal\block\BlockBase; +use Drupal\Core\Entity\EntityManager; +use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Session\AccountInterface; @@ -33,6 +35,13 @@ class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterf */ protected $blockManager; + /** + * The entity manager service. + * + * @var \Drupal\Core\Entity\EntityManagerInterface + */ + protected $entityManager; + /** * The Module Handler. * @@ -58,15 +67,18 @@ class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterf * The plugin implementation definition. * @param \Drupal\block\Plugin\Type\BlockManager * The Plugin Block Manager. + * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager + * The entity manager service. * @param \Drupal\Core\Extension\ModuleHandlerInterface * The Module Handler. * @param \Drupal\Core\Session\AccountInterface $account * The account for which view access should be checked. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, BlockManager $block_manager, ModuleHandlerInterface $module_handler, AccountInterface $account) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, BlockManager $block_manager, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, AccountInterface $account) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->blockManager = $block_manager; + $this->entityManager = $entity_manager; $this->moduleHandler = $module_handler; $this->account = $account; } @@ -80,6 +92,7 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_id, $plugin_definition, $container->get('plugin.manager.block'), + $container->get('entity.manager'), $container->get('module_handler'), $container->get('current_user') ); @@ -108,14 +121,9 @@ public function defaultConfiguration() { * Adds body and description fields to the block configuration form. */ public function blockForm($form, &$form_state) { - $options = array('default' => t('Default')); - $view_modes = entity_get_view_modes('custom_block'); - foreach ($view_modes as $view_mode => $detail) { - $options[$view_mode] = $detail['label']; - } $form['custom_block']['view_mode'] = array( '#type' => 'select', - '#options' => $options, + '#options' => $this->entityManager->getViewModeOptions('custom_block'), '#title' => t('View mode'), '#description' => t('Output the block in this view mode.'), '#default_value' => $this->configuration['view_mode'] diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php index dd349b85b0a83c8bf425b913f126551dea9957a7..4111596feb20b82b196b1d0a1e135f06d37b841a 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php @@ -80,7 +80,6 @@ public function testCustomBlockCreation() { // Test the available view mode options. $this->assertOption('edit-settings-custom-block-view-mode', 'default', 'The default view mode is available.'); - $this->assertOption('edit-settings-custom-block-view-mode', 'full', 'The full view mode is available.'); // Check that the block exists in the database. $blocks = entity_load_multiple_by_properties('custom_block', array('info' => $edit['info'])); diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/row/Rss.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/row/Rss.php index 063738c839bc769da0c7266168cfffcd33bea6e0..91fc249754d700864254f9a98d557379fedf2602 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/row/Rss.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/row/Rss.php @@ -74,7 +74,7 @@ public function preRender($result) { * in views_plugin_row_comment|node_rss.inc */ function options_form_summary_options() { - $view_modes = entity_get_view_modes('node'); + $view_modes = \Drupal::entityManager()->getViewModes('node'); $options = array(); foreach ($view_modes as $mode => $settings) { $options[$mode] = $settings['label']; diff --git a/core/modules/edit/lib/Drupal/edit/EditController.php b/core/modules/edit/lib/Drupal/edit/EditController.php index e5d3a87aa7230dbf404595651cda6a62d994b077..a086d9362a2fbc536b5e63ddbd630768d4054c66 100644 --- a/core/modules/edit/lib/Drupal/edit/EditController.php +++ b/core/modules/edit/lib/Drupal/edit/EditController.php @@ -265,7 +265,7 @@ public function fieldForm(EntityInterface $entity, $field_name, $langcode, $view * @see hook_edit_render_field() */ protected function renderField(EntityInterface $entity, $field_name, $langcode, $view_mode_id) { - $entity_view_mode_ids = array_keys(entity_get_view_modes($entity->getEntityTypeId())); + $entity_view_mode_ids = array_keys($this->entityManager()->getViewModes($entity->getEntityTypeId())); if (in_array($view_mode_id, $entity_view_mode_ids)) { $entity = \Drupal::entityManager()->getTranslationFromContext($entity, $langcode); $output = $entity->get($field_name)->view($view_mode_id); diff --git a/core/modules/entity/lib/Drupal/entity/Entity/EntityFormMode.php b/core/modules/entity/lib/Drupal/entity/Entity/EntityFormMode.php index 4e5848547f520bfb557203fba6ca790b1d3ff5a3..b9e8fcbe1ebc47771bb1a389b8792685d075f075 100644 --- a/core/modules/entity/lib/Drupal/entity/Entity/EntityFormMode.php +++ b/core/modules/entity/lib/Drupal/entity/Entity/EntityFormMode.php @@ -24,14 +24,14 @@ * display settings, or just replicate the settings of the 'default' form mode, * thus reducing the amount of form display configurations to keep track of. * - * @see entity_get_form_modes() + * @see \Drupal\Core\Entity\EntityManagerInterface::getAllFormModes() + * @see \Drupal\Core\Entity\EntityManagerInterface::getFormModes() * @see hook_entity_form_mode_info_alter() * * @ConfigEntityType( * id = "form_mode", * label = @Translation("Form mode"), * controllers = { - * "storage" = "Drupal\entity\EntityDisplayModeStorageController", * "list_builder" = "Drupal\entity\EntityFormModeListBuilder", * "form" = { * "add" = "Drupal\entity\Form\EntityFormModeAddForm", diff --git a/core/modules/entity/lib/Drupal/entity/Entity/EntityViewMode.php b/core/modules/entity/lib/Drupal/entity/Entity/EntityViewMode.php index df31790051de06a4d6db4caf7b062c3535480cab..221de9c73188a21187458661ff2dba397086a881 100644 --- a/core/modules/entity/lib/Drupal/entity/Entity/EntityViewMode.php +++ b/core/modules/entity/lib/Drupal/entity/Entity/EntityViewMode.php @@ -25,7 +25,8 @@ * replicate the settings of the 'default' view mode, thus reducing the amount * of display configurations to keep track of. * - * @see entity_get_view_modes() + * @see \Drupal\Core\Entity\EntityManagerInterface::getAllViewModes() + * @see \Drupal\Core\Entity\EntityManagerInterface::getViewModes() * @see hook_entity_view_mode_info_alter() * * @ConfigEntityType( diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php index 699718bd753f168620783f5aad067c88fb3e6201..a5c9909b4935725aa7d1b6a8850925b9bfd8ea33 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php @@ -9,6 +9,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Config\Entity\ConfigEntityInterface; +use Drupal\Core\Entity\EntityStorageControllerInterface; /** * Base class for config entity types that hold settings for form and view modes. @@ -88,4 +89,20 @@ public function calculateDependencies() { return $this->dependencies; } + /** + * {@inheritdoc} + */ + public function preSave(EntityStorageControllerInterface $storage_controller) { + parent::preSave($storage_controller); + \Drupal::entityManager()->clearCachedDefinitions(); + } + + /** + * {@inheritdoc} + */ + public static function preDelete(EntityStorageControllerInterface $storage_controller, array $entities) { + parent::preDelete($storage_controller, $entities); + \Drupal::entityManager()->clearCachedDefinitions(); + } + } diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayModeStorageController.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeStorageController.php deleted file mode 100644 index cca791ec5a4418a527661276e7fdb26d8f6a6c79..0000000000000000000000000000000000000000 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayModeStorageController.php +++ /dev/null @@ -1,32 +0,0 @@ -getFieldSetting('target_type')); - $options = array('default' => t('Default')); - foreach ($view_modes as $view_mode => $view_mode_settings) { - $options[$view_mode] = $view_mode_settings['label']; - } - $elements['view_mode'] = array( '#type' => 'select', - '#options' => $options, + '#options' => \Drupal::entityManager()->getViewModeOptions($this->getFieldSetting('target_type')), '#title' => t('View mode'), '#default_value' => $this->getSetting('view_mode'), '#required' => TRUE, @@ -61,12 +55,9 @@ public function settingsForm(array $form, array &$form_state) { public function settingsSummary() { $summary = array(); - $view_modes = entity_get_view_modes($this->getFieldSetting('target_type')); + $view_modes = \Drupal::entityManager()->getViewModeOptions($this->getFieldSetting('target_type')); $view_mode = $this->getSetting('view_mode'); - if ($view_mode == 'default') { - $view_mode = t('Default'); - } - $summary[] = t('Rendered as @mode', array('@mode' => isset($view_modes[$view_mode]['label']) ? $view_modes[$view_mode]['label'] : $view_mode)); + $summary[] = t('Rendered as @mode', array('@mode' => isset($view_modes[$view_mode]) ? $view_modes[$view_mode] : $view_mode)); $summary[] = $this->getSetting('links') ? t('Display links') : t('Do not display links'); return $summary; diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php index 35bef11a76b43eeda9acbcd011ac99f95cecbf39..384d76f1796f155afc3728f8864527dd033d341b 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php @@ -438,11 +438,11 @@ public static function postDelete(EntityStorageControllerInterface $storage_cont $displays_to_update = array(); foreach ($instances as $instance) { if (!$instance->deleted) { - $view_modes = array('default' => array()) + entity_get_view_modes($instance->entity_type); + $view_modes = \Drupal::entityManager()->getViewModeOptions($instance->entity_type, TRUE); foreach (array_keys($view_modes) as $mode) { $displays_to_update['entity_view_display'][$instance->entity_type . '.' . $instance->bundle . '.' . $mode][] = $instance->field->name; } - $form_modes = array('default' => array()) + entity_get_form_modes($instance->entity_type); + $form_modes = \Drupal::entityManager()->getFormModeOptions($instance->entity_type, TRUE); foreach (array_keys($form_modes) as $mode) { $displays_to_update['entity_form_display'][$instance->entity_type . '.' . $instance->bundle . '.' . $mode][] = $instance->field->name; } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php index f310d65fca9ca627a9f31bc33dcef65399b131bd..592f0a58c9b30ec77e57564e84e2f70146abf850 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php @@ -176,7 +176,7 @@ protected function getDefaultPlugin($field_type) { * {@inheritdoc} */ protected function getDisplayModes() { - return entity_get_view_modes($this->entity_type); + return $this->entityManager->getViewModes($this->entity_type); } /** diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php index 1f508d4952e09ab6364b0c16350ca8e8a15d096c..2e19fb977163c0c550f248f19a142a33fa933a6e 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php @@ -143,7 +143,7 @@ protected function getDefaultPlugin($field_type) { * {@inheritdoc} */ protected function getDisplayModes() { - return entity_get_form_modes($this->entity_type); + return $this->entityManager->getFormModes($this->entity_type); } /** diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Plugin/Derivative/FieldUiLocalTask.php b/core/modules/field_ui/lib/Drupal/field_ui/Plugin/Derivative/FieldUiLocalTask.php index b29144fb30ac4303305ca266775bf425a965b406..f7fd862f213b08e1081c7ad4be1937fed4db8ef9 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Plugin/Derivative/FieldUiLocalTask.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Plugin/Derivative/FieldUiLocalTask.php @@ -134,7 +134,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { // One local task for each form mode. $weight = 0; - foreach (entity_get_form_modes($entity_type_id) as $form_mode => $form_mode_info) { + foreach ($this->entityManager->getFormModes($entity_type_id) as $form_mode => $form_mode_info) { $this->derivatives['field_form_display_' . $form_mode . '_' . $entity_type_id] = array( 'title' => $form_mode_info['label'], 'route_name' => "field_ui.form_display_overview_form_mode_$entity_type_id", @@ -148,7 +148,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { // One local task for each view mode. $weight = 0; - foreach (entity_get_view_modes($entity_type_id) as $view_mode => $form_mode_info) { + foreach ($this->entityManager->getViewModes($entity_type_id) as $view_mode => $form_mode_info) { $this->derivatives['field_display_' . $view_mode . '_' . $entity_type_id] = array( 'title' => $form_mode_info['label'], 'route_name' => "field_ui.display_overview_view_mode_$entity_type_id", @@ -185,11 +185,11 @@ public function alterLocalTasks(&$local_tasks) { $local_tasks["field_ui.fields:field_form_display_default_$entity_type"]['base_route'] = $admin_form; $local_tasks["field_ui.fields:field_display_default_$entity_type"]['base_route'] = $admin_form; - foreach (entity_get_form_modes($entity_type) as $form_mode => $form_mode_info) { + foreach ($this->entityManager->getFormModes($entity_type) as $form_mode => $form_mode_info) { $local_tasks['field_ui.fields:field_form_display_' . $form_mode . '_' . $entity_type]['base_route'] = $admin_form; } - foreach (entity_get_view_modes($entity_type) as $view_mode => $form_mode_info) { + foreach ($this->entityManager->getViewModes($entity_type) as $view_mode => $form_mode_info) { $local_tasks['field_ui.fields:field_display_' . $view_mode . '_' . $entity_type]['base_route'] = $admin_form; } } diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/row/Rss.php b/core/modules/node/lib/Drupal/node/Plugin/views/row/Rss.php index ce505084fbb58a5a60a312873a3feac256abe915..2df6281b245a98188b4567cc6835679a7a6f37d2 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/row/Rss.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/row/Rss.php @@ -62,7 +62,7 @@ public function buildOptionsForm(&$form, &$form_state) { * Return the main options, which are shown in the summary title. */ public function buildOptionsForm_summary_options() { - $view_modes = entity_get_view_modes('node'); + $view_modes = \Drupal::entityManager()->getViewModes('node'); $options = array(); foreach ($view_modes as $mode => $settings) { $options[$mode] = $settings['label']; diff --git a/core/modules/node/node.module b/core/modules/node/node.module index ba5151f48f7a74ec90b13e8a0231665994b1985f..a226e592c9b46d894fcf4216b0c402f3f6785cc8 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -429,7 +429,7 @@ function node_add_body_field(NodeTypeInterface $type, $label = 'Body') { // The teaser view mode is created by the Standard profile and therefore // might not exist. - $view_modes = entity_get_view_modes('node'); + $view_modes = \Drupal::entityManager()->getViewModes('node'); if (isset($view_modes['teaser'])) { entity_get_display('node', $type->type, 'teaser') ->setComponent('body', array( diff --git a/core/modules/system/entity.api.php b/core/modules/system/entity.api.php index ab25a74d9da326414e41cd2a955daf35844fb3b2..c6cb1d96eb53c050836e64b06cd028b73bcb5d0e 100644 --- a/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -144,7 +144,8 @@ function hook_entity_type_alter(array &$entity_types) { * @param array $view_modes * An array of view modes, keyed first by entity type, then by view mode name. * - * @see entity_get_view_modes() + * @see \Drupal\Core\Entity\EntityManagerInterface::getAllViewModes() + * @see \Drupal\Core\Entity\EntityManagerInterface::getViewModes() * @see hook_entity_view_mode_info() */ function hook_entity_view_mode_info_alter(&$view_modes) { diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/Entity.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/Entity.php index 634395ebbbcead6b8eb635122e102fe49c3c1c57..27dc95a37e32921da6c9d9ebcd976822b51943e0 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/Entity.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/Entity.php @@ -57,10 +57,9 @@ protected function defineOptions() { public function buildOptionsForm(&$form, &$form_state) { parent::buildOptionsForm($form, $form_state); - $options = $this->buildViewModeOptions(); $form['view_mode'] = array( '#type' => 'select', - '#options' => $options, + '#options' => \Drupal::entityManager()->getViewModeOptions($this->entityType), '#title' => t('View mode'), '#default_value' => $this->options['view_mode'], ); @@ -79,22 +78,6 @@ public function buildOptionsForm(&$form, &$form_state) { ); } - /** - * Return the main options, which are shown in the summary title. - * - * @return array - * All view modes of the entity type. - */ - protected function buildViewModeOptions() { - $options = array('default' => t('Default')); - $view_modes = entity_get_view_modes($this->entityType); - foreach ($view_modes as $mode => $settings) { - $options[$mode] = $settings['label']; - } - - return $options; - } - /** * {@inheritdoc} */ diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/row/EntityRow.php b/core/modules/views/lib/Drupal/views/Plugin/views/row/EntityRow.php index 2ca0dc9093417a0b0bfa480b9bb312358c1895ab..6e8843b0c52252407390ba5bedb8f2f6e242030a 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/row/EntityRow.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/row/EntityRow.php @@ -128,10 +128,9 @@ protected function defineOptions() { public function buildOptionsForm(&$form, &$form_state) { parent::buildOptionsForm($form, $form_state); - $options = $this->buildViewModeOptions(); $form['view_mode'] = array( '#type' => 'select', - '#options' => $options, + '#options' => \Drupal::entityManager()->getViewModeOptions($this->entityTypeId), '#title' => t('View mode'), '#default_value' => $this->options['view_mode'], ); @@ -146,19 +145,6 @@ public function buildOptionsForm(&$form, &$form_state) { ); } - /** - * Return the main options, which are shown in the summary title. - */ - protected function buildViewModeOptions() { - $options = array('default' => t('Default')); - $view_modes = entity_get_view_modes($this->entityTypeId); - foreach ($view_modes as $mode => $settings) { - $options[$mode] = $settings['label']; - } - - return $options; - } - /** * Returns the available rendering strategies for language-aware entities. * @@ -178,7 +164,7 @@ protected function buildRenderingLanguageOptions() { * Overrides Drupal\views\Plugin\views\PluginBase::summaryTitle(). */ public function summaryTitle() { - $options = $this->buildViewModeOptions(); + $options = \Drupal::entityManager()->getViewModeOptions($this->entityTypeId); if (isset($options[$this->options['view_mode']])) { return String::checkPlain($options[$this->options['view_mode']]); } diff --git a/core/modules/views/lib/Drupal/views/Tests/Handler/AreaEntityTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaEntityTest.php index 81374f72a8cd91119d6c280b8d65967af331f271..b1d766bbbb94276b343c1f2472e26029825bc8ff 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Handler/AreaEntityTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaEntityTest.php @@ -8,6 +8,7 @@ namespace Drupal\views\Tests\Handler; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Language\Language; use Drupal\views\Tests\ViewTestBase; use Drupal\views\Views; @@ -101,6 +102,11 @@ public function testEntityArea() { $this->assertTrue(strpos(trim((string) $result[0]), $entities[1]->label()) !== FALSE, 'The rendered entity appears in the footer of the view.'); $this->assertTrue(strpos(trim((string) $result[0]), 'full') !== FALSE, 'The rendered entity appeared in the right view mode.'); + // Mark entity_test test view_mode as customizable. + $view_mode = \Drupal::entityManager()->getStorageController('view_mode')->load('entity_test.test'); + $view_mode->status = TRUE; + $view_mode->save(); + // Change the view mode of the area handler. $view = Views::getView('test_entity_area'); $item = $view->getHandler('default', 'header', 'entity_entity_test'); @@ -126,7 +132,6 @@ public function testEntityArea() { $form_state = array(); $form_state['type'] = 'header'; $view->display_handler->getHandler('header', 'entity_entity_test')->buildOptionsForm($form, $form_state); - $this->assertTrue(isset($form['view_mode']['#options']['full']), 'Ensure that the full view mode is available.'); $this->assertTrue(isset($form['view_mode']['#options']['test']), 'Ensure that the test view mode is available.'); $this->assertTrue(isset($form['view_mode']['#options']['default']), 'Ensure that the default view mode is available.'); } diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/RowEntityTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/RowEntityTest.php index bb479044b62b08dd64dac8a73732c40145c448ff..5fa35b88cda13bf43f8f8db5f68307aa272e5df5 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/RowEntityTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/RowEntityTest.php @@ -78,7 +78,6 @@ public function testEntityRow() { $form_state['view'] = $view->storage; $view->rowPlugin->buildOptionsForm($form, $form_state); - $this->assertTrue(isset($form['view_mode']['#options']['full']), 'Ensure that the full view mode is available'); $this->assertTrue(isset($form['view_mode']['#options']['default']), 'Ensure that the default view mode is available'); }