diff --git a/core/lib/Drupal/Core/Entity/ViewMode/EntityViewMode.php b/core/lib/Drupal/Core/Entity/ViewMode/EntityViewMode.php index 47f2078..d8f6bc9 100644 --- a/core/lib/Drupal/Core/Entity/ViewMode/EntityViewMode.php +++ b/core/lib/Drupal/Core/Entity/ViewMode/EntityViewMode.php @@ -45,17 +45,40 @@ class EntityViewMode extends ConfigEntityBase { */ public $bundles = array(); + /** + * The entity type this view mode is used for. + * + * @var string + */ public $type; + /** + * Whether or not this view mode has custom settings in the Field UI. + * + * @var bool + */ public $custom = FALSE; /** + * Whether or not this view mode can be removed. + * + * @var bool + */ + public $locked = FALSE; + + /** * Overrides Drupal\Core\Core\Entity\Entity::id(). */ public function id() { return $this->name; } + /** + * Returns the raw view mode name, exluding the entity type. + * + * @return string + * The raw view mode name. + */ public function name() { $name = strtok($this->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 23a7a33..ae04d51 100644 --- a/core/modules/comment/config/view_mode.comment.full.yml +++ b/core/modules/comment/config/view_mode.comment.full.yml @@ -2,3 +2,4 @@ name: comment.full label: Full comment custom: '0' type: comment +locked: '1' 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 646057c..3f9fefc 100644 --- a/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeFormController.php +++ b/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeFormController.php @@ -77,6 +77,16 @@ function ($option) use ($view_mode) { } /** + * Overrides Drupal\Core\Entity\EntityFormController::actions(). + */ + protected function actions(array $form, array &$form_state) { + $view_mode = $this->getEntity($form_state); + $actions = parent::actions($form, $form_state); + $actions['delete']['#access'] = !$view_mode->locked; + return $actions; + } + + /** * Overrides Drupal\Core\Entity\EntityFormController::validate(). */ public function validate(array $form, array &$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 d4cfab7..ebbf75a 100644 --- a/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeListController.php +++ b/core/modules/entity_ui/lib/Drupal/entity_ui/ViewModeListController.php @@ -56,6 +56,17 @@ public function buildRow(EntityInterface $view_mode) { } /** + * Overrides Drupal\Core\Entity\EntityListController::getOperations(); + */ + public function getOperations(EntityInterface $view_mode) { + $operations = parent::getOperations($view_mode); + if ($view_mode->locked) { + unset($operations['delete']); + } + return $operations; + } + + /** * Overrides Drupal\Core\Entity\EntityListController::buildRow(); */ public function render() { diff --git a/core/modules/file/config/view_mode.file.full.yml b/core/modules/file/config/view_mode.file.full.yml index c8065a1..44bea6c 100644 --- a/core/modules/file/config/view_mode.file.full.yml +++ b/core/modules/file/config/view_mode.file.full.yml @@ -2,3 +2,4 @@ name: file.full label: 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 1614340..ecd11ea 100644 --- a/core/modules/node/config/view_mode.node.full.yml +++ b/core/modules/node/config/view_mode.node.full.yml @@ -2,3 +2,4 @@ name: node.full label: 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 96213fe..aec7364 100644 --- a/core/modules/node/config/view_mode.node.rss.yml +++ b/core/modules/node/config/view_mode.node.rss.yml @@ -2,3 +2,4 @@ name: node.rss label: 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 d5dd1f4..005d8e0 100644 --- a/core/modules/node/config/view_mode.node.teaser.yml +++ b/core/modules/node/config/view_mode.node.teaser.yml @@ -2,3 +2,4 @@ name: node.teaser label: 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 a8155bc..9d9441e 100644 --- a/core/modules/search/config/view_mode.node.search_index.yml +++ b/core/modules/search/config/view_mode.node.search_index.yml @@ -2,3 +2,4 @@ name: node.search_index label: 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 9e8b02f..5539901 100644 --- a/core/modules/search/config/view_mode.node.search_result.yml +++ b/core/modules/search/config/view_mode.node.search_result.yml @@ -2,3 +2,4 @@ name: node.search_result label: Search result custom: '0' type: node +locked: '1' 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 03ccf14..4e9e70b 100644 --- a/core/modules/taxonomy/config/view_mode.taxonomy_term.full.yml +++ b/core/modules/taxonomy/config/view_mode.taxonomy_term.full.yml @@ -2,3 +2,4 @@ name: taxonomy_term.full label: 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 0b32697..2545a2c 100644 --- a/core/modules/taxonomy/config/view_mode.taxonomy_vocabulary.full.yml +++ b/core/modules/taxonomy/config/view_mode.taxonomy_vocabulary.full.yml @@ -2,3 +2,4 @@ name: taxonomy_vocabulary.full label: 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 a1fd93f..0c05b19 100644 --- a/core/modules/user/config/view_mode.user.full.yml +++ b/core/modules/user/config/view_mode.user.full.yml @@ -2,3 +2,4 @@ name: user.full label: User account custom: '0' type: user +locked: '1'