summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-03-25 09:43:08 (GMT)
committerAlex Pott2014-03-25 09:43:08 (GMT)
commit02f761ba1d67eb02edea2246662c6b08b9655a09 (patch)
tree5b899acaa7804bb9a3fb74bb831260fd71b04762
parent5909b03b34321a866a29297a9631098eddccdf5a (diff)
Issue #2154711 by plopesc, tim.plunkett, olli, Berdir, Dave Reid: Move entity_get_(form/view)_mode_options() functions to EntityManager and add get(Form/View)ModeOptions() methods.
-rw-r--r--core/includes/entity.inc69
-rw-r--r--core/lib/Drupal/Core/Entity/EntityManager.php127
-rw-r--r--core/lib/Drupal/Core/Entity/EntityManagerInterface.php64
-rw-r--r--core/lib/Drupal/Core/Entity/EntityViewBuilder.php2
-rw-r--r--core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Block/CustomBlockBlock.php22
-rw-r--r--core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php1
-rw-r--r--core/modules/comment/lib/Drupal/comment/Plugin/views/row/Rss.php2
-rw-r--r--core/modules/edit/lib/Drupal/edit/EditController.php2
-rw-r--r--core/modules/entity/lib/Drupal/entity/Entity/EntityFormMode.php4
-rw-r--r--core/modules/entity/lib/Drupal/entity/Entity/EntityViewMode.php3
-rw-r--r--core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php17
-rw-r--r--core/modules/entity/lib/Drupal/entity/EntityDisplayModeStorageController.php32
-rw-r--r--core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php15
-rw-r--r--core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php4
-rw-r--r--core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php2
-rw-r--r--core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php2
-rw-r--r--core/modules/field_ui/lib/Drupal/field_ui/Plugin/Derivative/FieldUiLocalTask.php8
-rw-r--r--core/modules/node/lib/Drupal/node/Plugin/views/row/Rss.php2
-rw-r--r--core/modules/node/node.module2
-rw-r--r--core/modules/system/entity.api.php3
-rw-r--r--core/modules/views/lib/Drupal/views/Plugin/views/area/Entity.php19
-rw-r--r--core/modules/views/lib/Drupal/views/Plugin/views/row/EntityRow.php18
-rw-r--r--core/modules/views/lib/Drupal/views/Tests/Handler/AreaEntityTest.php7
-rw-r--r--core/modules/views/lib/Drupal/views/Tests/Plugin/RowEntityTest.php1
24 files changed, 272 insertions, 156 deletions
diff --git a/core/includes/entity.inc b/core/includes/entity.inc
index 2859b59..761e386 100644
--- a/core/includes/entity.inc
+++ b/core/includes/entity.inc
@@ -14,7 +14,6 @@ use Drupal\Core\Language\Language;
* 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 00c9d73..0e8e6b8 100644
--- a/core/lib/Drupal/Core/Entity/EntityManager.php
+++ b/core/lib/Drupal/Core/Entity/EntityManager.php
@@ -115,6 +115,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.
*
* @param \Traversable $namespaces
@@ -155,6 +162,7 @@ class EntityManager extends PluginManagerBase implements EntityManagerInterface
parent::clearCachedDefinitions();
$this->bundleInfo = NULL;
+ $this->displayModeInfo = array();
}
/**
@@ -509,4 +517,123 @@ class EntityManager extends PluginManagerBase implements EntityManagerInterface
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 9a65866..bb8e0d9 100644
--- a/core/lib/Drupal/Core/Entity/EntityManagerInterface.php
+++ b/core/lib/Drupal/Core/Entity/EntityManagerInterface.php
@@ -235,4 +235,68 @@ interface EntityManagerInterface extends PluginManagerInterface {
*/
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 2e48ecc..798fdef 100644
--- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php
+++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php
@@ -362,7 +362,7 @@ class EntityViewBuilder extends EntityControllerBase implements EntityController
// 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 dab9b26..e05089e 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;
@@ -34,6 +36,13 @@ class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterf
protected $blockManager;
/**
+ * The entity manager service.
+ *
+ * @var \Drupal\Core\Entity\EntityManagerInterface
+ */
+ protected $entityManager;
+
+ /**
* The Module Handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface.
@@ -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 @@ class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterf
$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 @@ class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterf
* 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 dd349b8..4111596 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 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
// 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 063738c..91fc249 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 @@ class Rss extends RowPluginBase {
* 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 e5d3a87..a086d93 100644
--- a/core/modules/edit/lib/Drupal/edit/EditController.php
+++ b/core/modules/edit/lib/Drupal/edit/EditController.php
@@ -265,7 +265,7 @@ class EditController extends ControllerBase {
* @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 4e58485..b9e8fcb 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 @@ use Drupal\entity\EntityFormModeInterface;
* 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 df31790..221de9c 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 @@ use Drupal\entity\EntityViewModeInterface;
* 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 699718b..a5c9909 100644
--- a/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php
+++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php
@@ -9,6 +9,7 @@ namespace Drupal\entity;
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 @@ abstract class EntityDisplayModeBase extends ConfigEntityBase implements EntityD
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 cca791e..0000000
--- a/core/modules/entity/lib/Drupal/entity/EntityDisplayModeStorageController.php
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\entity\EntityDisplayModeStorageController.
- */
-
-namespace Drupal\entity;
-
-use Drupal\Core\Config\Entity\ConfigStorageController;
-use Drupal\Core\Entity\EntityInterface;
-
-/**
- * Defines the storage controller class for entity form and view modes.
- */
-class EntityDisplayModeStorageController extends ConfigStorageController {
-
- /**
- * {@inheritdoc}
- */
- protected function preSave(EntityInterface $view_mode) {
- entity_info_cache_clear();
- }
-
- /**
- * {@inheritdoc}
- */
- protected function preDelete($view_modes) {
- entity_info_cache_clear();
- }
-
-}
diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php
index 40e3c39..bebc01a 100644
--- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php
+++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php
@@ -32,15 +32,9 @@ class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase {
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state) {
- $view_modes = entity_get_view_modes($this->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 @@ class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase {
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 35bef11..384d76f 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 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
$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 f310d65..592f0a5 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 @@ class DisplayOverview extends DisplayOverviewBase {
* {@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 1f508d4..2e19fb9 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 @@ class FormDisplayOverview extends DisplayOverviewBase {
* {@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 b29144f..f7fd862 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 @@ class FieldUiLocalTask extends DerivativeBase implements ContainerDerivativeInte
// 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 @@ class FieldUiLocalTask extends DerivativeBase implements ContainerDerivativeInte
// 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 @@ class FieldUiLocalTask extends DerivativeBase implements ContainerDerivativeInte
$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 ce50508..2df6281 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 @@ class Rss extends RowPluginBase {
* 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 ba5151f..a226e59 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 ab25a74..c6cb1d9 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 634395e..27dc95a 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 @@ class Entity extends TokenizeAreaPluginBase {
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'],
);
@@ -80,22 +79,6 @@ class Entity extends TokenizeAreaPluginBase {
}
/**
- * 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}
*/
public function render($empty = FALSE) {
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 2ca0dc9..6e8843b 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 @@ class EntityRow extends RowPluginBase {
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'],
);
@@ -147,19 +146,6 @@ class EntityRow extends RowPluginBase {
}
/**
- * 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.
*
* @return array
@@ -178,7 +164,7 @@ class EntityRow extends RowPluginBase {
* 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 81374f7..b1d766b 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 @@ class AreaEntityTest extends ViewTestBase {
$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 @@ class AreaEntityTest extends ViewTestBase {
$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 bb47904..5fa35b8 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 @@ class RowEntityTest extends ViewUnitTestBase {
$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');
}