diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 323f212..0eda220 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -80,19 +80,11 @@ function entity_get_info($entity_type = NULL) { } // Add view modes. - $view_modes = drupal_container()->get('config.storage')->listAll('view_mode.'); - foreach ($view_modes as $config_name) { - // Load the config directly, entity_load() would cause recursion. - $view_mode = config($config_name)->get(); - $name = strtok($view_mode['name'], '.'); - $name = strtok('.'); - - if (isset($view_mode['type']) && !empty($name) && isset($entity_info[$view_mode['type']])) { - $entity_info[$view_mode['type']]['view modes'][$name] = array( - 'label' => check_plain($view_mode['label']), - 'custom settings' => $view_mode['custom'], - ); - } + foreach (entity_load_multiple('view_mode') as $view_mode) { + $entity_info[$view_mode->type]['view modes'][$view_mode->name()] = array( + 'label' => check_plain($view_mode->label()), + 'custom settings' => $view_mode->custom, + ); } // Let other modules alter the entity info. diff --git a/core/lib/Drupal/Core/Entity/ViewMode/EntityViewMode.php b/core/lib/Drupal/Core/Entity/ViewMode/EntityViewMode.php index 2b55b4a..a4125dd 100644 --- a/core/lib/Drupal/Core/Entity/ViewMode/EntityViewMode.php +++ b/core/lib/Drupal/Core/Entity/ViewMode/EntityViewMode.php @@ -15,11 +15,11 @@ class EntityViewMode extends ConfigEntityBase { /** - * The name of the view mode. + * The machine name of the view mode. * * @var string */ - public $name; + public $machine_name; /** * The UUID of the view mode. @@ -33,17 +33,7 @@ class EntityViewMode extends ConfigEntityBase { * * @var string */ - public $label; - - /** - * An array of entity types that use this view mode. - * - * The array is keyed by the entity type, and the value is either the entity - * type if this view mode is used, or 0 if it is not. - * - * @var array - */ - public $bundles = array(); + public $name; /** * The entity type this view mode is used for. @@ -70,7 +60,7 @@ class EntityViewMode extends ConfigEntityBase { * Overrides Drupal\Core\Core\Entity\Entity::id(). */ public function id() { - return $this->name; + return $this->machine_name; } /** @@ -80,7 +70,7 @@ public function id() { * The raw view mode name. */ public function name() { - $name = strtok($this->name, '.'); + $name = strtok($this->machine_name, '.'); return strtok('.'); } diff --git a/core/modules/comment/config/view_mode.comment.full.yml b/core/modules/comment/config/view_mode.comment.full.yml index ae04d51..43b6233 100644 --- a/core/modules/comment/config/view_mode.comment.full.yml +++ b/core/modules/comment/config/view_mode.comment.full.yml @@ -1,5 +1,5 @@ -name: comment.full -label: Full comment +machine_name: comment.full +name: Full comment custom: '0' type: comment locked: '1' diff --git a/core/modules/entity_ui/entity_ui.admin.inc b/core/modules/entity_ui/entity_ui.admin.inc index bc55f47..8f23cd8 100644 --- a/core/modules/entity_ui/entity_ui.admin.inc +++ b/core/modules/entity_ui/entity_ui.admin.inc @@ -2,7 +2,7 @@ /** * @file - * Administrative functions for custom view modes. + * Administrative functions for view modes. */ /** @@ -13,11 +13,7 @@ function entity_ui_view_mode_list() { $controller = entity_list_controller('view_mode'); foreach (entity_get_info() as $type => $info) { if ($type != 'view_mode') { - $build[$type] = array( - '#type' => 'fieldset', - '#title' => $info['label'], - ); - $build[$type]['view_modes'] = $controller->set($type)->render(); + $build[$type] = $controller->set($type)->render(); } } return $build; diff --git a/core/modules/entity_ui/entity_ui.module b/core/modules/entity_ui/entity_ui.module index 3e46791..07f59da 100644 --- a/core/modules/entity_ui/entity_ui.module +++ b/core/modules/entity_ui/entity_ui.module @@ -13,8 +13,11 @@ function entity_ui_help($path, $arg) { switch ($path) { case 'admin/help#entity_ui': + return '

' . t('@todo.') . '

'; + case 'admin/config/system/view-modes': return '

' . t("View modes let entities be displayed differently depending on the context. For instance, a node can be displayed differently on its own page ('full' mode), on the home page or taxonomy listings ('teaser' mode), or in an RSS feed ('rss' mode). Modules taking part in the display of the entity (notably the Field API) can adjust their behavior depending on the requested view mode.") . '

'; + } } @@ -24,7 +27,7 @@ function entity_ui_help($path, $arg) { function entity_ui_permission() { return array( 'administer view modes' => array( - 'title' => t('Add, edit and delete custom view modes.'), + 'title' => t('Add, edit and delete view modes.'), ), ); } @@ -46,7 +49,7 @@ function entity_ui_entity_info_alter(&$entity_info) { function entity_ui_menu() { $items['admin/config/system/view-modes'] = array( 'title' => 'View modes', - 'description' => 'Manage custom view modes.', + 'description' => 'Configure view modes for content, file, or user displays.', 'page callback' => 'entity_ui_view_mode_list', 'access arguments' => array('administer view modes'), 'file' => 'entity_ui.admin.inc', @@ -76,7 +79,7 @@ function entity_ui_menu() { } /** - * Loads a custom view mode by machine name. + * Loads a view mode by machine name. */ function view_mode_load($machine_name) { return entity_load('view_mode', $machine_name); diff --git a/core/modules/entity_ui/lib/Drupal/entity_ui/Tests/ViewModeTest.php b/core/modules/entity_ui/lib/Drupal/entity_ui/Tests/ViewModeTest.php index d5b3ee7..5114d91 100644 --- a/core/modules/entity_ui/lib/Drupal/entity_ui/Tests/ViewModeTest.php +++ b/core/modules/entity_ui/lib/Drupal/entity_ui/Tests/ViewModeTest.php @@ -24,7 +24,7 @@ class ViewModeTest extends WebTestBase { public static function getInfo() { return array( 'name' => 'View modes', - 'description' => 'Tests for managing custom view modes.', + 'description' => 'Tests for managing view modes.', 'group' => 'Entity UI', ); } @@ -37,29 +37,15 @@ function setUp() { } /** - * Creates a view mode. - * - * @param array $edit - * (optional) An array of view mode properties. Defaults to an empty array. - */ - function createViewMode(&$edit = array()) { - $edit += array( - 'label' => 'Testing', - 'name' => 'testing', - 'custom' => TRUE, - 'bundles[article]' => TRUE, - ); - - $this->drupalPost('admin/config/system/view-modes/add/node', $edit, t('Save')); - $this->assertText(format_string('Saved the !name view mode.', array('!name' => $edit['label']))); - } - - /** * Tests managing view modes. */ function testManageViewModes() { - $edit = array(); - $this->createViewMode($edit); + $edit = array( + 'name' => 'Testing', + 'machine_name' => 'testing', + ); + $this->drupalPost('admin/config/system/view-modes/add/node', $edit, t('Save')); + $this->assertText(format_string('Saved the !name view mode.', array('!name' => $edit['name']))); // Create the same and assert it already exists. $this->drupalPost('admin/config/system/view-modes/add/node', $edit, t('Save')); @@ -75,7 +61,7 @@ function testManageViewModes() { // Update view mode label. $edit = array( - 'label' => 'Testing 2', + 'name' => 'Testing 2', ); $this->drupalPost('admin/config/system/view-modes/node.testing/edit', $edit, t('Save')); $this->assertText('Saved the Testing 2 view mode.', 'Testing label updated.'); diff --git a/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeFormController.php b/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeFormController.php index edac556..a7f499c 100644 --- a/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeFormController.php +++ b/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeFormController.php @@ -25,54 +25,25 @@ public function form(array $form, array &$form_state, EntityInterface $view_mode '#title' => t('Entity type'), '#markup' => $entity_info['label'], ); - $form['label'] = array( + $form['name'] = array( '#type' => 'textfield', - '#title' => t('Label'), - '#default_value' => $view_mode->label, + '#title' => t('Name'), + '#default_value' => $view_mode->label(), '#required' => TRUE, ); - $form['name'] = array( + $form['machine_name'] = array( '#type' => 'machine_name', '#machine_name' => array( - 'source' => array('label'), + 'source' => array('name'), 'exists' => 'entity_ui_view_mode_exists', ), '#entity_type' => $view_mode->type, '#default_value' => $view_mode->name(), - '#disabled' => !empty($view_mode->label), + '#disabled' => !$view_mode->isNew(), '#field_prefix' => "$view_mode->type.", ); - $form['custom'] = array( - '#type' => 'checkbox', - '#title' => t('Use custom display settings'), - '#description' => t('Unchecking this will delete all the display settings for this view mode.'), - '#default_value' => $view_mode->custom, - ); - - $form['bundles'] = array( - '#type' => 'checkboxes', - '#title' => t('Enable this view mode for the following types'), - '#description' => t('Unchecking a type that has already been configured will delete the display settings for this view mode.'), - '#options' => array_map(function ($bundle) { - return $bundle['label']; - }, $entity_info['bundles'] - ), - '#default_value' => array_filter( - array_keys($entity_info['bundles']), - function ($option) use ($view_mode) { - $settings = field_view_mode_settings($view_mode->type, $option); - return !empty($settings[$view_mode->name()]['custom_settings']); - } - ), - '#states' => array( - 'visible' => array( - ':input[name="custom"]' => array('checked' => TRUE), - ), - ), - ); - return $form; } @@ -91,7 +62,7 @@ protected function actions(array $form, array &$form_state) { */ public function validate(array $form, array &$form_state) { $entity = clone $this->getEntity($form_state); - form_set_value($form['name'], $entity->type . '.' . $form_state['values']['name'], $form_state); + form_set_value($form['machine_name'], $entity->type . '.' . $form_state['values']['machine_name'], $form_state); parent::validate($form, $form_state); } diff --git a/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeListController.php b/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeListController.php index 2c554a4..7c7010b 100644 --- a/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeListController.php +++ b/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeListController.php @@ -37,10 +37,8 @@ public function load() { * Overrides Drupal\Core\Entity\EntityListController::buildHeader(); */ public function buildHeader() { - $header = parent::buildHeader(); - $operations = array_pop($header); - $header['custom'] = t('Custom settings'); - $header['operations'] = $operations; + $header['name'] = t('Name'); + $header['operations'] = t('Operations'); return $header; } @@ -48,9 +46,7 @@ public function buildHeader() { * Overrides Drupal\Core\Entity\EntityListController::buildRow(); */ public function buildRow(EntityInterface $view_mode) { - $row['label'] = $view_mode->label(); - $row['id'] = $view_mode->name(); - $row['custom'] = $view_mode->custom ? t('Yes') : t('No'); + $row['name'] = $view_mode->label(); $row['operations']['data'] = $this->buildOperations($view_mode); return $row; } @@ -82,6 +78,7 @@ public function render() { ), 'colspan' => count($build['#header']), ); + $build['#caption'] = $this->type['label']; return $build; } diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index e21e77b..87c7a50 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -415,14 +415,3 @@ function field_ui_library_info() { return $libraries; } - -/** - * Implements hook_view_mode_presave(). - */ -function field_ui_view_mode_presave(EntityInterface $view_mode) { - foreach ($view_mode->bundles as $bundle => $custom) { - $bundle_settings = field_bundle_settings($view_mode->type, $bundle); - $bundle_settings['view_modes'][$view_mode->name()]['custom_settings'] = (bool) $custom; - field_bundle_settings($view_mode->type, $bundle, $bundle_settings); - } -} diff --git a/core/modules/file/config/view_mode.file.full.yml b/core/modules/file/config/view_mode.file.full.yml index 44bea6c..4746580 100644 --- a/core/modules/file/config/view_mode.file.full.yml +++ b/core/modules/file/config/view_mode.file.full.yml @@ -1,5 +1,5 @@ -name: file.full -label: File default +machine_name: file.full +name: File default custom: '0' type: file locked: '1' diff --git a/core/modules/node/config/view_mode.node.full.yml b/core/modules/node/config/view_mode.node.full.yml index ecd11ea..0e667c5 100644 --- a/core/modules/node/config/view_mode.node.full.yml +++ b/core/modules/node/config/view_mode.node.full.yml @@ -1,5 +1,5 @@ -name: node.full -label: Full content +machine_name: node.full +name: Full content custom: '0' type: node locked: '1' diff --git a/core/modules/node/config/view_mode.node.rss.yml b/core/modules/node/config/view_mode.node.rss.yml index aec7364..7b36134 100644 --- a/core/modules/node/config/view_mode.node.rss.yml +++ b/core/modules/node/config/view_mode.node.rss.yml @@ -1,5 +1,5 @@ -name: node.rss -label: RSS +machine_name: node.rss +name: RSS custom: '0' type: node locked: '1' diff --git a/core/modules/node/config/view_mode.node.teaser.yml b/core/modules/node/config/view_mode.node.teaser.yml index 005d8e0..63efd07 100644 --- a/core/modules/node/config/view_mode.node.teaser.yml +++ b/core/modules/node/config/view_mode.node.teaser.yml @@ -1,5 +1,5 @@ -name: node.teaser -label: Teaser +machine_name: node.teaser +name: Teaser custom: '1' type: node locked: '1' diff --git a/core/modules/search/config/view_mode.node.search_index.yml b/core/modules/search/config/view_mode.node.search_index.yml index 9d9441e..0324aba 100644 --- a/core/modules/search/config/view_mode.node.search_index.yml +++ b/core/modules/search/config/view_mode.node.search_index.yml @@ -1,5 +1,5 @@ -name: node.search_index -label: Search index +machine_name: node.search_index +name: Search index custom: '0' type: node locked: '1' diff --git a/core/modules/search/config/view_mode.node.search_result.yml b/core/modules/search/config/view_mode.node.search_result.yml index 5539901..da28216 100644 --- a/core/modules/search/config/view_mode.node.search_result.yml +++ b/core/modules/search/config/view_mode.node.search_result.yml @@ -1,5 +1,5 @@ -name: node.search_result -label: Search result +machine_name: node.search_result +name: Search result custom: '0' type: node locked: '1' diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 83c767a..2a1809b 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1092,8 +1092,8 @@ function system_entity_info() { 'config prefix' => 'view_mode', 'fieldable' => FALSE, 'entity keys' => array( - 'id' => 'name', - 'label' => 'label', + 'id' => 'machine_name', + 'label' => 'name', 'uuid' => 'uuid', ), ), diff --git a/core/modules/taxonomy/config/view_mode.taxonomy_term.full.yml b/core/modules/taxonomy/config/view_mode.taxonomy_term.full.yml index 4e9e70b..99dca2d 100644 --- a/core/modules/taxonomy/config/view_mode.taxonomy_term.full.yml +++ b/core/modules/taxonomy/config/view_mode.taxonomy_term.full.yml @@ -1,5 +1,5 @@ -name: taxonomy_term.full -label: Taxonomy term page +machine_name: taxonomy_term.full +name: Taxonomy term page custom: '0' type: taxonomy_term locked: '1' diff --git a/core/modules/taxonomy/config/view_mode.taxonomy_vocabulary.full.yml b/core/modules/taxonomy/config/view_mode.taxonomy_vocabulary.full.yml index 2545a2c..f689959 100644 --- a/core/modules/taxonomy/config/view_mode.taxonomy_vocabulary.full.yml +++ b/core/modules/taxonomy/config/view_mode.taxonomy_vocabulary.full.yml @@ -1,5 +1,5 @@ -name: taxonomy_vocabulary.full -label: Taxonomy vocabulary default +machine_name: taxonomy_vocabulary.full +name: Taxonomy vocabulary default custom: '0' type: taxonomy_vocabulary locked: '1' diff --git a/core/modules/user/config/view_mode.user.full.yml b/core/modules/user/config/view_mode.user.full.yml index 0c05b19..283935e 100644 --- a/core/modules/user/config/view_mode.user.full.yml +++ b/core/modules/user/config/view_mode.user.full.yml @@ -1,5 +1,5 @@ -name: user.full -label: User account +machine_name: user.full +name: User account custom: '0' type: user locked: '1'