diff --git a/core/modules/views/config/schema/views.display.schema.yml b/core/modules/views/config/schema/views.display.schema.yml index 0735cadc36..56150f583f 100644 --- a/core/modules/views/config/schema/views.display.schema.yml +++ b/core/modules/views/config/schema/views.display.schema.yml @@ -68,9 +68,9 @@ views.display.page: menu_name: type: string label: 'Menu name' - enforce_admin_theme: + always_use_admin_theme: type: boolean - label: 'Enforce admin theme' + label: 'Always use admin theme' views.display.block: type: views_display diff --git a/core/modules/views/src/Plugin/views/display/Page.php b/core/modules/views/src/Plugin/views/display/Page.php index 9f064e588c..278bfa3a9e 100644 --- a/core/modules/views/src/Plugin/views/display/Page.php +++ b/core/modules/views/src/Plugin/views/display/Page.php @@ -93,10 +93,10 @@ protected function getRoute($view_id, $display_id) { // Explicitly set HTML as the format for Page displays. $route->setRequirement('_format', 'html'); - // Add the _admin_route option only if 'enforce_admin_theme' display option + // Add the _admin_route option only if always_use_admin_theme display option // is TRUE. Otherwise, let other modules or alters to make a decision. // @see \Drupal\system\EventSubscriber\AdminRouteSubscriber::alterRoutes() - if ($this->getOption('enforce_admin_theme')) { + if ($this->getOption('always_use_admin_theme')) { $route->setOption('_admin_route', TRUE); } @@ -158,7 +158,7 @@ protected function defineOptions() { 'weight' => ['default' => 0], ], ]; - $options['enforce_admin_theme'] = ['default' => FALSE]; + $options['always_use_admin_theme'] = ['default' => FALSE]; return $options; } @@ -239,8 +239,8 @@ public function optionsSummary(&$categories, &$options) { $options['menu']['links']['tab_options'] = $this->t('Change settings for the parent menu'); } - if ($this->getOption('enforce_admin_theme')) { - $options['path']['value'] .= ' ' . $this->t('(using admin theme)'); + if ($this->getOption('always_use_admin_theme')) { + $options['path']['value'] .= ' ' . $this->t('(Using admin theme)'); } } @@ -455,11 +455,11 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { ]; break; case 'path': - $form['enforce_admin_theme'] = [ + $form['always_use_admin_theme'] = [ '#type' => 'checkbox', - '#title' => $this->t('Enforce this page to be displayed in the admin theme'), - '#description' => $this->t('Paths starting with /admin/ are always shown in the admin theme. If checked, pages on other paths are shown in the admin theme as well.'), - '#default_value' => $this->getOption('enforce_admin_theme'), + '#title' => $this->t('Always use admin theme'), + '#description' => $this->t('Paths starting with /admin/ use the admin theme even when this is not set.'), + '#default_value' => $this->getOption('always_use_admin_theme'), ]; break; } @@ -512,7 +512,7 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) { $this->setOption('tab_options', $form_state->getValue('tab_options')); break; case 'path': - $this->setOption('enforce_admin_theme', $form_state->getValue('enforce_admin_theme')); + $this->setOption('always_use_admin_theme', $form_state->getValue('always_use_admin_theme')); break; } } diff --git a/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php b/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php index 63569320f7..6b86c356bc 100644 --- a/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php @@ -163,7 +163,7 @@ public function testAdminTheme() { $this->assertSession()->responseNotContains('seven/css/base/elements.css'); $view = $this->config('views.view.test_page_display'); - $view->set('display.page_3.display_options.enforce_admin_theme', TRUE)->save(); + $view->set('display.page_3.display_options.always_use_admin_theme', TRUE)->save(); $this->container->get('router.builder')->rebuild(); // Check that the page was served with the administrative theme. diff --git a/core/modules/views/tests/src/Functional/Update/EnforceAdminThemeOptionUpdateTest.php b/core/modules/views/tests/src/Functional/Update/AlwaysUseAdminThemeOptionUpdateTest.php similarity index 50% rename from core/modules/views/tests/src/Functional/Update/EnforceAdminThemeOptionUpdateTest.php rename to core/modules/views/tests/src/Functional/Update/AlwaysUseAdminThemeOptionUpdateTest.php index 7ecda74f6a..18c7f67079 100644 --- a/core/modules/views/tests/src/Functional/Update/EnforceAdminThemeOptionUpdateTest.php +++ b/core/modules/views/tests/src/Functional/Update/AlwaysUseAdminThemeOptionUpdateTest.php @@ -5,11 +5,11 @@ use Drupal\FunctionalTests\Update\UpdatePathTestBase; /** - * Tests Views administrative theme page display option update. + * Tests the addition of the admin theme option for views with page displays. * * @group views */ -class EnforceAdminThemeOptionUpdateTest extends UpdatePathTestBase { +class AlwaysUseAdminThemeOptionUpdateTest extends UpdatePathTestBase { /** * {@inheritdoc} @@ -21,25 +21,25 @@ protected function setDatabaseDumpFiles() { } /** - * Tests views_post_update_enforce_admin_theme(). + * Tests views_post_update_always_use_admin_theme(). * - * @see views_post_update_enforce_admin_theme() + * @see views_post_update_always_use_admin_theme() */ public function testViewsPostUpdateEnforceAdminTheme() { $options = $this->config('views.view.content') ->get('display.page_1.display_options'); - // Check that enforce_admin_theme option doesn't exist in 'content' view. - $this->assertArrayNotHasKey('enforce_admin_theme', $options); + // Check that always_use_admin_theme option doesn't exist in 'content' view. + $this->assertArrayNotHasKey('always_use_admin_theme', $options); // Run updates. $this->runUpdates(); $options = $this->config('views.view.content') ->get('display.page_1.display_options'); - // Check that enforce_admin_theme option was added in 'content'. - $this->assertArrayHasKey('enforce_admin_theme', $options); - // Check that enforce_admin_theme option is FALSE. - $this->assertFalse($options['enforce_admin_theme']); + // Check that always_use_admin_theme option was added in 'content' view. + $this->assertArrayHasKey('always_use_admin_theme', $options); + // Check that always_use_admin_theme option is FALSE. + $this->assertFalse($options['always_use_admin_theme']); } } diff --git a/core/modules/views/views.post_update.php b/core/modules/views/views.post_update.php index 3fc8093cf8..318cd2f912 100644 --- a/core/modules/views/views.post_update.php +++ b/core/modules/views/views.post_update.php @@ -272,18 +272,23 @@ function views_post_update_bulk_field_moved() { } /** - * Fix views with page display administrative theme option. + * Add administrative theme option for views with page displays. */ -function views_post_update_enforce_admin_theme() { +function views_post_update_always_use_admin_theme() { $config_factory = \Drupal::configFactory(); foreach ($config_factory->listAll('views.view.') as $name) { $view = $config_factory->getEditable($name); + $changed = FALSE; foreach ($view->get('display') as $display_id => $display) { // Deal only with page displays. if ($display['display_plugin'] == 'page') { - $trail = "display.$display_id.display_options.enforce_admin_theme"; - $view->set($trail, FALSE)->save(); + $trail = "display.$display_id.display_options.always_use_admin_theme"; + $view->set($trail, FALSE); + $changed = TRUE; } } + if ($changed) { + $view->save(); + } } }