diff --git a/core/modules/views/src/Plugin/views/display/Page.php b/core/modules/views/src/Plugin/views/display/Page.php index 914b8a6..8eda228 100644 --- a/core/modules/views/src/Plugin/views/display/Page.php +++ b/core/modules/views/src/Plugin/views/display/Page.php @@ -219,11 +219,9 @@ public function optionsSummary(&$categories, &$options) { $options['menu']['links']['tab_options'] = $this->t('Change settings for the parent menu'); } - $options['admin_theme'] = [ - 'category' => 'page', - 'title' => $this->t('Use admin theme'), - 'value' => $this->getOption('admin_theme') ? 'Yes' : 'No', - ]; + if ($this->getOption('admin_theme')) { + $options['path']['value'] .= ' ' . $this->t('(using admin theme)'); + } } /** @@ -436,10 +434,10 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { ), ); break; - case 'admin_theme': + case 'path': $form['admin_theme'] = [ '#type' => 'checkbox', - '#title' => $this->t('Use admin theme'), + '#title' => $this->t('Use admin theme for this page'), '#description' => $this->t('If checked, the admin theme will be used to display this page.'), '#default_value' => $this->getOption('admin_theme'), ]; @@ -493,7 +491,7 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) { case 'tab_options': $this->setOption('tab_options', $form_state->getValue('tab_options')); break; - case 'admin_theme': + case 'path': $this->setOption('admin_theme', $form_state->getValue('admin_theme')); break; } @@ -560,8 +558,12 @@ public function calculateDependencies() { */ protected function getRoute($view_id, $display_id) { $route = parent::getRoute($view_id, $display_id); - // Add the _admin_route option to route. - $route->setOption('_admin_route', $this->getOption('admin_theme')); + // Add the _admin_route option only if '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('admin_theme')) { + $route->setOption('_admin_route', TRUE); + } return $route; } diff --git a/core/modules/views/src/Tests/Plugin/DisplayPageWebTest.php b/core/modules/views/src/Tests/Plugin/DisplayPageWebTest.php index bac35fd..2c5361e 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayPageWebTest.php +++ b/core/modules/views/src/Tests/Plugin/DisplayPageWebTest.php @@ -147,6 +147,30 @@ public function testPagePaths() { } /** + * Tests the 'admin_theme' page display option. + */ + public function testAdminTheme() { + $account = $this->drupalCreateUser(['view the administration theme']); + $this->drupalLogin($account); + + // Use distinct default and administrative themes for this test. + $this->container->get('theme_handler')->install(['seven']); + $this->config('system.theme')->set('admin', 'seven')->save(); + + // Check that the page has been served with the default theme. + $this->drupalGet('test_page_display_200'); + $this->assertNoRaw('seven/css/base/elements.css'); + + $view = $this->config('views.view.test_page_display'); + $view->set('display.page_3.display_options.admin_theme', TRUE)->save(); + $this->container->get('router.builder')->rebuild(); + + // Check that the page was served with the administrative theme. + $this->drupalGet('test_page_display_200'); + $this->assertRaw('seven/css/base/elements.css'); + } + + /** * Tests that we can successfully change a view page display path. * * @param string $path