diff --git b/core/lib/Drupal/Core/Entity/EntityManager.php a/core/lib/Drupal/Core/Entity/EntityManager.php
index 0c8ad84..7b73915 100644
--- b/core/lib/Drupal/Core/Entity/EntityManager.php
+++ a/core/lib/Drupal/Core/Entity/EntityManager.php
@@ -251,10 +251,11 @@ protected function processDefinition(&$definition, $plugin_id) {
// Add view modes.
// We cannot use entity_load_multiple() as that leads to recursion.
$view_modes = drupal_container()->get('config.storage')->listAll('view_mode.');
+ $config_factory = drupal_container()->get('config.factory');
foreach ($view_modes as $config_name) {
- $view_mode = config($config_name)->get();
- if ($view_mode['type'] == $plugin_id) {
- $entity_type = strtok($view_mode['machine_name'], '.');
+ $view_mode = $config_factory->get($config_name)->load()->get();
+ if ($view_mode['targetEntityType'] == $plugin_id) {
+ $entity_type = strtok($view_mode['machineName'], '.');
$definition['view_modes'][strtok('.')] = array(
'label' => check_plain($view_mode['name']),
'custom_settings' => $view_mode['custom'],
diff --git b/core/lib/Drupal/Core/Entity/ViewMode/EntityViewModeStorageController.php a/core/lib/Drupal/Core/Entity/ViewMode/EntityViewModeStorageController.php
new file mode 100644
index 0000000..fb597b1
--- /dev/null
+++ a/core/lib/Drupal/Core/Entity/ViewMode/EntityViewModeStorageController.php
@@ -0,0 +1,32 @@
+machine_name;
+ return $this->machineName;
}
/**
@@ -87,7 +95,7 @@ public function id() {
* The raw view mode name.
*/
public function name() {
- $name = strtok($this->machine_name, '.');
+ $name = strtok($this->machineName, '.');
return strtok('.');
}
diff --git b/core/modules/book/config/view_mode.node.print.yml a/core/modules/book/config/view_mode.node.print.yml
index 1ed8183..df756d1 100644
--- b/core/modules/book/config/view_mode.node.print.yml
+++ a/core/modules/book/config/view_mode.node.print.yml
@@ -1,5 +1,5 @@
-machine_name: node.print
+machineName: node.print
name: Print
custom: '0'
-type: node
+targetEntityType: node
locked: '1'
diff --git b/core/modules/comment/config/view_mode.comment.full.yml a/core/modules/comment/config/view_mode.comment.full.yml
index 43b6233..6de56e7 100644
--- b/core/modules/comment/config/view_mode.comment.full.yml
+++ a/core/modules/comment/config/view_mode.comment.full.yml
@@ -1,5 +1,5 @@
-machine_name: comment.full
+machineName: comment.full
name: Full comment
custom: '0'
-type: comment
+targetEntityType: comment
locked: '1'
diff --git b/core/modules/entity_ui/css/entity_ui.admin.css a/core/modules/entity_ui/css/entity_ui.admin.css
index 53093a1..1927418 100644
--- b/core/modules/entity_ui/css/entity_ui.admin.css
+++ a/core/modules/entity_ui/css/entity_ui.admin.css
@@ -7,9 +7,3 @@
width: 100px;
}
-table caption {
- font-size: 110%;
- font-weight: bold;
- text-align: left;
- padding-bottom: 0.5em;
-}
diff --git b/core/modules/entity_ui/entity_ui.admin.inc a/core/modules/entity_ui/entity_ui.admin.inc
index af636cd..fce7b93 100644
--- b/core/modules/entity_ui/entity_ui.admin.inc
+++ a/core/modules/entity_ui/entity_ui.admin.inc
@@ -13,9 +13,11 @@ function entity_ui_view_mode_list() {
$weight = 0;
$controller = entity_list_controller('view_mode');
foreach (entity_get_info() as $type => $info) {
- if ($type != 'view_mode' && !empty($info['fieldable'])) {
- $build[$type] = $controller->set($type)->render();
- // Content is usually the most important entity type in the system.
+ // @todo Revisit the assumption that only content entities can have view modes.
+ if (is_subclass_of($info['entity_class'], 'Drupal\Core\Entity\ContentEntityInterface')) {
+ $build[$type]['title']['#markup'] = '
' . check_plain($info['label']) . '
';
+ $build[$type]['table'] = $controller->set($type)->render();
+ // Node is usually the most important entity type in the system.
$build[$type]['#weight'] = ($type == 'node') ? -10 : $weight++;
}
}
diff --git b/core/modules/entity_ui/entity_ui.module a/core/modules/entity_ui/entity_ui.module
index 03bc1a6..dc09293 100644
--- b/core/modules/entity_ui/entity_ui.module
+++ a/core/modules/entity_ui/entity_ui.module
@@ -5,8 +5,6 @@
* Provides a user interface for the Entity API.
*/
-use Drupal\Core\Entity\EntityInterface;
-
/**
* Implements hook_help().
*/
@@ -91,6 +89,12 @@ function entity_ui_menu() {
/**
* Loads a view mode by machine name.
+ *
+ * This knowingly violates the standard of prefixing function names with the
+ * module name in order to provide the %view_mode menu wildcard.
+ *
+ * @param string $machine_name
+ * The machine name of the view mode in the form "$entity_type.$name".
*/
function view_mode_load($machine_name) {
return entity_load('view_mode', $machine_name);
@@ -98,23 +102,14 @@ function view_mode_load($machine_name) {
/**
* Checks for an existing view mode.
+ *
+ * @param string $typed_machine_name
+ * The machine name as it was typed in a form element of type 'machine_name'.
+ *
+ * @param array $element
+ * The form element of type 'machine_name' that is being checked.
*/
-function entity_ui_view_mode_exists($machine_name, $element) {
- return entity_load('view_mode', $element['#entity_type'] . ".$machine_name");
-}
-
-/**
- * Implements hook_view_mode_presave().
- */
-function entity_ui_view_mode_presave(EntityInterface $entity) {
- entity_info_cache_clear();
- state()->set('menu_rebuild_needed', TRUE);
+function entity_ui_view_mode_exists($typed_machine_name, $element) {
+ return entity_load('view_mode', $element['#entity_type'] . ".$typed_machine_name");
}
-/**
- * Implements hook_view_mode_delete().
- */
-function entity_ui_view_mode_delete(EntityInterface $entity) {
- entity_info_cache_clear();
- state()->set('menu_rebuild_needed', TRUE);
-}
diff --git b/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeFormController.php a/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeFormController.php
index 5fd192c..c4d2f58 100644
--- b/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeFormController.php
+++ a/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeFormController.php
@@ -7,7 +7,7 @@
namespace Drupal\entity_ui;
-use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Plugin\Core\Entity\EntityViewMode;
use Drupal\Core\Entity\EntityFormController;
/**
@@ -18,8 +18,8 @@ class ViewModeFormController extends EntityFormController {
/**
* Overrides Drupal\Core\Entity\EntityFormController::form().
*/
- public function form(array $form, array &$form_state, EntityInterface $view_mode) {
- $entity_info = entity_get_info($view_mode->type);
+ public function form(array $form, array &$form_state, EntityViewMode $view_mode) {
+ $entity_info = entity_get_info($view_mode->targetEntityType);
$form['type'] = array(
'#type' => 'item',
'#title' => t('Entity type'),
@@ -38,7 +38,7 @@ public function form(array $form, array &$form_state, EntityInterface $view_mode
'source' => array('name'),
'exists' => 'entity_ui_view_mode_exists',
),
- '#entity_type' => $view_mode->type,
+ '#entity_type' => $view_mode->targetEntityType,
'#default_value' => $view_mode->name(),
'#disabled' => !$view_mode->isNew(),
'#field_prefix' => "$view_mode->type.",
@@ -61,8 +61,8 @@ protected function actions(array $form, array &$form_state) {
* Overrides Drupal\Core\Entity\EntityFormController::validate().
*/
public function validate(array $form, array &$form_state) {
- $entity = clone $this->getEntity($form_state);
- form_set_value($form['machine_name'], $entity->type . '.' . $form_state['values']['machine_name'], $form_state);
+ $view_mode = clone $this->getEntity($form_state);
+ form_set_value($form['machine_name'], $view_mode->targetEntityType . '.' . $form_state['values']['machine_name'], $form_state);
parent::validate($form, $form_state);
}
diff --git b/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeListController.php a/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeListController.php
index f612d91..d8e2d86 100644
--- b/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeListController.php
+++ a/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeListController.php
@@ -8,33 +8,60 @@
namespace Drupal\entity_ui;
use Drupal\Core\Config\Entity\ConfigEntityListController;
-use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Plugin\Core\Entity\EntityViewMode;
/**
* Provides a listing of view modes.
*/
class ViewModeListController extends ConfigEntityListController {
- protected $type;
+ /**
+ * The name of the entity type this list of view modes is for.
+ *
+ * @var string
+ */
+ protected $targetEntityType;
- public function set($type) {
- $this->type = entity_get_info($type);
- $this->type['type'] = $type;
+ /**
+ * The entity info of the entity type this of view modes is for.
+ *
+ * @var array
+ */
+ protected $targetEntityInfo;
+
+ /**
+ * Sets the entity type that will be used for the view mode listing.
+ *
+ * @param string $entity_type
+ * The entity type whose view modes should be listed.
+ *
+ * @return \Drupal\entity_ui\ViewModeListController
+ * The object itself.
+ */
+ public function set($entity_type) {
+ $this->targetEntityType = $entity_type;
+ $this->targetEntityInfo = entity_get_info($entity_type);
return $this;
}
/**
* Overrides Drupal\Core\Entity\EntityListController::load().
+ *
+ * Loads only those view modes that belong to the given target entity type.
*/
public function load() {
- $type = $this->type['type'];
- return array_filter(parent::load(), function ($entity) use ($type) {
- return $entity->type == $type;
+ $entity_type = $this->targetEntityType;
+ return array_filter(parent::load(), function ($entity) use ($entity_type) {
+ return $entity->targetEntityType == $entity_type;
});
}
/**
- * Overrides Drupal\Core\Entity\EntityListController::buildHeader();
+ * Overrides Drupal\Core\Entity\EntityListController::buildHeader().
+ *
+ * Removes the 'Machine name' column.
+ *
+ * @todo Move this to EntityListController: http://drupal.org/node/1831890
*/
public function buildHeader() {
$header['name'] = t('Name');
@@ -43,9 +70,9 @@ public function buildHeader() {
}
/**
- * Overrides Drupal\Core\Entity\EntityListController::buildRow();
+ * Overrides Drupal\Core\Entity\EntityListController::buildRow().
*/
- public function buildRow(EntityInterface $view_mode) {
+ public function buildRow(EntityViewMode $view_mode) {
$row['name'] = check_plain($view_mode->label());
$row['operations']['data'] = $this->buildOperations($view_mode);
$row['operations']['class'] = array('operations');
@@ -53,10 +80,11 @@ public function buildRow(EntityInterface $view_mode) {
}
/**
- * Overrides Drupal\Core\Entity\EntityListController::getOperations();
+ * Overrides Drupal\Core\Entity\EntityListController::getOperations().
*/
- public function getOperations(EntityInterface $view_mode) {
+ public function getOperations(EntityViewMode $view_mode) {
$operations = parent::getOperations($view_mode);
+ // @todo Move this to ConfigEntityBase: http://drupal.org/node/1831928
if ($view_mode->locked) {
unset($operations['delete']);
}
@@ -64,22 +92,21 @@ public function getOperations(EntityInterface $view_mode) {
}
/**
- * Overrides Drupal\Core\Entity\EntityListController::buildRow();
+ * Overrides Drupal\Core\Entity\EntityListController::buildRow().
*/
public function render() {
$build = parent::render();
$build['#rows']['_add_new'][] = array(
'data' => array(
'#type' => 'link',
- '#href' => 'admin/config/system/view-modes/add/' . $this->type['type'],
- '#title' => t('Add new %type view mode', array('%type' => $this->type['label'])),
+ '#href' => 'admin/config/system/view-modes/add/' . $this->targetEntityType,
+ '#title' => t('Add new %type view mode', array('%type' => $this->targetEntityInfo['label'])),
'#options' => array(
'html' => TRUE,
),
),
'colspan' => count($build['#header']),
);
- $build['#caption'] = check_plain($this->type['label']);
return $build;
}
diff --git b/core/modules/field_ui/field_ui.module a/core/modules/field_ui/field_ui.module
index 28fc056..052ad4b 100644
--- b/core/modules/field_ui/field_ui.module
+++ a/core/modules/field_ui/field_ui.module
@@ -5,7 +5,7 @@
* Allows administrators to attach custom fields to fieldable types.
*/
-use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Plugin\Core\Entity\EntityViewMode;
/**
* Implements hook_help().
@@ -415,3 +415,18 @@ function field_ui_library_info() {
return $libraries;
}
+
+/**
+ * Implements hook_view_mode_presave().
+ */
+function field_ui_view_mode_presave(EntityViewMode $view_mode) {
+ state()->set('menu_rebuild_needed', TRUE);
+}
+
+/**
+ * Implements hook_view_mode_delete().
+ */
+function field_ui_view_mode_delete(EntityViewMode $view_mode) {
+ state()->set('menu_rebuild_needed', TRUE);
+}
+
diff --git b/core/modules/file/config/view_mode.file.full.yml a/core/modules/file/config/view_mode.file.full.yml
index 4746580..872254e 100644
--- b/core/modules/file/config/view_mode.file.full.yml
+++ a/core/modules/file/config/view_mode.file.full.yml
@@ -1,5 +1,5 @@
machine_name: file.full
name: File default
custom: '0'
-type: file
+targetEntityType: file
locked: '1'
diff --git b/core/modules/node/config/view_mode.node.full.yml a/core/modules/node/config/view_mode.node.full.yml
index 0e667c5..4630674 100644
--- b/core/modules/node/config/view_mode.node.full.yml
+++ a/core/modules/node/config/view_mode.node.full.yml
@@ -1,5 +1,5 @@
-machine_name: node.full
+machineName: node.full
name: Full content
custom: '0'
-type: node
+targetEntityType: node
locked: '1'
diff --git b/core/modules/node/config/view_mode.node.rss.yml a/core/modules/node/config/view_mode.node.rss.yml
index 7b36134..6de18d1 100644
--- b/core/modules/node/config/view_mode.node.rss.yml
+++ a/core/modules/node/config/view_mode.node.rss.yml
@@ -1,5 +1,5 @@
-machine_name: node.rss
+machineName: node.rss
name: RSS
custom: '0'
-type: node
+targetEntityType: node
locked: '1'
diff --git b/core/modules/node/config/view_mode.node.teaser.yml a/core/modules/node/config/view_mode.node.teaser.yml
index 63efd07..e7478ad 100644
--- b/core/modules/node/config/view_mode.node.teaser.yml
+++ a/core/modules/node/config/view_mode.node.teaser.yml
@@ -1,5 +1,5 @@
-machine_name: node.teaser
+machineName: node.teaser
name: Teaser
custom: '1'
-type: node
+targetEntityType: node
locked: '1'
diff --git b/core/modules/search/config/view_mode.node.search_index.yml a/core/modules/search/config/view_mode.node.search_index.yml
index 0324aba..32fab57 100644
--- b/core/modules/search/config/view_mode.node.search_index.yml
+++ a/core/modules/search/config/view_mode.node.search_index.yml
@@ -1,5 +1,5 @@
-machine_name: node.search_index
+machineName: node.search_index
name: Search index
custom: '0'
-type: node
+targetEntityType: node
locked: '1'
diff --git b/core/modules/search/config/view_mode.node.search_result.yml a/core/modules/search/config/view_mode.node.search_result.yml
index da28216..da2d0d2 100644
--- b/core/modules/search/config/view_mode.node.search_result.yml
+++ a/core/modules/search/config/view_mode.node.search_result.yml
@@ -1,5 +1,5 @@
-machine_name: node.search_result
+machineName: node.search_result
name: Search result
custom: '0'
-type: node
+targetEntityType: node
locked: '1'
diff --git b/core/modules/system/system.install a/core/modules/system/system.install
index e15bc12..1bfb90c 100644
--- b/core/modules/system/system.install
+++ a/core/modules/system/system.install
@@ -2229,16 +2229,20 @@ function system_update_8034() {
'taxonomy_term' => array(
'full' => 'Taxonomy term page',
),
+ 'taxonomy_vocabulary' => array(
+ 'full' => 'Taxonomy vocabulary',
+ ),
);
foreach ($entity_view_modes as $entity_type => $view_modes) {
foreach ($view_modes as $key => $name) {
+ $custom = ($key == 'teaser');
config('view_mode.' . $entity_type . '.' . $key)
- ->set('machine_name', $entity_type . '.' . $key)
+ ->set('machineName', $entity_type . '.' . $key)
->set('name', $name)
- ->set('type', $entity_type)
+ ->set('targetEntityType', $entity_type)
->set('locked', TRUE)
- ->set('custom', FALSE)
+ ->set('custom', $custom)
->save();
}
}
diff --git b/core/modules/taxonomy/config/view_mode.taxonomy_term.full.yml a/core/modules/taxonomy/config/view_mode.taxonomy_term.full.yml
index 99dca2d..37af637 100644
--- b/core/modules/taxonomy/config/view_mode.taxonomy_term.full.yml
+++ a/core/modules/taxonomy/config/view_mode.taxonomy_term.full.yml
@@ -1,5 +1,5 @@
-machine_name: taxonomy_term.full
+machineName: taxonomy_term.full
name: Taxonomy term page
custom: '0'
-type: taxonomy_term
+targetEntityType: taxonomy_term
locked: '1'
diff --git b/core/modules/taxonomy/config/view_mode.taxonomy_vocabulary.full.yml a/core/modules/taxonomy/config/view_mode.taxonomy_vocabulary.full.yml
new file mode 100644
index 0000000..d52effd
--- /dev/null
+++ a/core/modules/taxonomy/config/view_mode.taxonomy_vocabulary.full.yml
@@ -0,0 +1,5 @@
+machineName: vocabulary.full
+name: Taxonomy vocabulary
+custom: '0'
+targetEntityType: taxonomy_vocabulary
+locked: '1'
diff --git b/core/modules/user/config/view_mode.user.full.yml a/core/modules/user/config/view_mode.user.full.yml
index 283935e..020651b 100644
--- b/core/modules/user/config/view_mode.user.full.yml
+++ a/core/modules/user/config/view_mode.user.full.yml
@@ -1,5 +1,5 @@
-machine_name: user.full
+machineName: user.full
name: User account
custom: '0'
-type: user
+targetEntityType: user
locked: '1'