diff --git b/core/lib/Drupal/Core/Entity/EntityManager.php a/core/lib/Drupal/Core/Entity/EntityManager.php index 1b3104f..7a867b8 100644 --- b/core/lib/Drupal/Core/Entity/EntityManager.php +++ a/core/lib/Drupal/Core/Entity/EntityManager.php @@ -217,8 +217,6 @@ public function getDefinitions() { // @todo Remove array_filter() once http://drupal.org/node/1780396 is // resolved. $definitions = array_filter(parent::getDefinitions()); - // Allow to process all definitions at once. - $this->processDefinitions($definitions); cache($this->cacheBin)->set($this->cacheKey, $definitions, $this->cacheExpire, $this->cacheTags); return $definitions; } @@ -236,6 +234,19 @@ protected function processDefinition(&$definition, $plugin_id) { return; } + // Add view modes. + // We cannot use entity_load_multiple() as that leads to recursion. + $view_modes = drupal_container()->get('config.storage')->listAll('view_mode.'); + foreach ($view_modes as $config_name) { + $view_mode = config($config_name)->get(); + if ($view_mode['type'] == $plugin_id) { + $definition['view_modes'][$view_mode['machine_name']] = array( + 'label' => check_plain($view_mode['name']), + 'custom_settings' => $view_mode['custom'], + ); + } + } + // If no bundle key is provided, assume a single bundle, named after // the entity type. if (empty($definition['entity_keys']['bundle']) && empty($definition['bundles'])) { @@ -252,32 +263,4 @@ protected function processDefinition(&$definition, $plugin_id) { } } - /** - * Performs extra processing on all plugin definitions at once. - * - * @param array $definitions - * An array of all plugin definitions, keyed by plugin ID, passed by - * reference. - */ - protected function processDefinitions(&$definitions) { - // Add view modes. - // This cannot be done in EntityManager::processDefinition as finding out - // the view mode entity's controller class would require calling - // EntityManager::getDefinition(), which calls - // EntityManager::getDefinitions() leading to recursion. For the same - // reason, we cannot call entity_get_controller() but need to instantiate - // the class directly. - $controller = new $definitions['view_mode']['controller_class']('view_mode', $definitions['view_mode']); - foreach ($controller->load() as $view_mode) { - $definitions[$view_mode->type]['view_modes'][$view_mode->name()] = array( - // Entity::label() calls entity_get_info(), so we cannot use it here. - // Note the difference between $view_mode->name() and $view_mode->name. - // @todo Make this work for classes other than - // \Drupal\Core\Plugin\Core\Entity\EntityViewMode. - 'label' => check_plain($view_mode->name), - 'custom_settings' => $view_mode->custom, - ); - } - } - } diff --git b/core/modules/entity_ui/lib/Drupal/entity_ui/Tests/ViewModeTest.php a/core/modules/entity_ui/lib/Drupal/entity_ui/Tests/ViewModeTest.php index 5114d91..b135277 100644 --- b/core/modules/entity_ui/lib/Drupal/entity_ui/Tests/ViewModeTest.php +++ a/core/modules/entity_ui/lib/Drupal/entity_ui/Tests/ViewModeTest.php @@ -53,11 +53,11 @@ function testManageViewModes() { // Assert it's found on the Field UI for article. $this->drupalGet('admin/structure/types/manage/article/display'); - $this->assertRaw('view_modes_custom[testing]', 'Testing view mode found on node article.'); + $this->assertRaw('view_modes_custom[node.testing]', 'Testing view mode found on node article.'); // Assert it's not found on the Field UI for user. $this->drupalGet('admin/config/people/accounts/display'); - $this->assertNoRaw('view_modes_custom[testing]', 'Testing view mode not found on user.'); + $this->assertNoRaw('view_modes_custom[user.testing]', 'Testing view mode not found on user.'); // Update view mode label. $edit = array(