diff --git a/core/config/schema/core.data_types.schema.yml b/core/config/schema/core.data_types.schema.yml index 73db361..f1e8750 100644 --- a/core/config/schema/core.data_types.schema.yml +++ b/core/config/schema/core.data_types.schema.yml @@ -37,6 +37,9 @@ string: uri: label: 'Uri' class: '\Drupal\Core\TypedData\Plugin\DataType\Uri' +three_state: + label: 'Three state' + class: '\Drupal\Core\TypedData\Plugin\DataType\ThreeStateData' # Container data types for lists with known and unknown keys. mapping: diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/ThreeStateData.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/ThreeStateData.php new file mode 100644 index 0000000..353a24d --- /dev/null +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/ThreeStateData.php @@ -0,0 +1,31 @@ +value === NULL) { + return $this->value; + } + return parent::getCastedValue(); + } + +} diff --git a/core/lib/Drupal/Core/TypedData/Type/ThreeStateInterface.php b/core/lib/Drupal/Core/TypedData/Type/ThreeStateInterface.php new file mode 100644 index 0000000..4753418 --- /dev/null +++ b/core/lib/Drupal/Core/TypedData/Type/ThreeStateInterface.php @@ -0,0 +1,10 @@ + array('default' => 0), ), ); - $options['admin_theme'] = ['default' => FALSE]; + $options['admin_theme'] = ['default' => NULL]; return $options; } @@ -219,10 +219,6 @@ public function optionsSummary(&$categories, &$options) { $options['menu']['setting'] = $this->t('Parent menu item'); $options['menu']['links']['tab_options'] = $this->t('Change settings for the parent menu'); } - - if ($this->getOption('admin_theme')) { - $options['path']['value'] .= ' ' . $this->t('(using admin theme)'); - } } /** @@ -435,14 +431,6 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { ), ); break; - case 'path': - $form['admin_theme'] = [ - '#type' => 'checkbox', - '#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'), - ]; - break; } } @@ -492,9 +480,6 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) { case 'tab_options': $this->setOption('tab_options', $form_state->getValue('tab_options')); break; - case 'path': - $this->setOption('admin_theme', $form_state->getValue('admin_theme')); - break; } } @@ -559,11 +544,13 @@ public function calculateDependencies() { */ protected function getRoute($view_id, $display_id) { $route = parent::getRoute($view_id, $display_id); - // Add the _admin_route option only if 'admin_theme' display option is TRUE. - // Otherwise, let other modules or alters to make a decision. + // Add the _admin_route option only if 'admin_theme' display option + // is explicitly set to TRUE or FALSE. 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); + $admin_theme = $this->getOption('admin_theme'); + if ($admin_theme === TRUE || $admin_theme === FALSE) { + $route->setOption('_admin_route', $admin_theme); } return $route; } diff --git a/core/modules/views/src/Tests/Plugin/DisplayPageWebTest.php b/core/modules/views/src/Tests/Plugin/DisplayPageWebTest.php index 0ea2a31..66fb1ed 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayPageWebTest.php +++ b/core/modules/views/src/Tests/Plugin/DisplayPageWebTest.php @@ -19,7 +19,13 @@ class DisplayPageWebTest extends PluginTestBase { * * @var array */ - public static $testViews = array('test_page_display', 'test_page_display_arguments', 'test_page_display_menu', 'test_page_display_path'); + public static $testViews = [ + 'test_page_display', + 'test_page_display_arguments', + 'test_page_display_menu', + 'test_page_display_path', + 'test_page_display_admin_theme', + ]; /** * Modules to enable. @@ -150,24 +156,38 @@ 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(); + $account = $this->drupalCreateUser(['view the administration theme']); + $this->drupalLogin($account); - // Check that the page was served with the administrative theme. - $this->drupalGet('test_page_display_200'); - $this->assertRaw('seven/css/base/elements.css'); + // We are testing next displays from the 'test_page_display_admin_theme' + // view. The key is the display id, the value a boolean indicating if the + // page is expected to be displayed with the admin theme. + $page_displays = [ + // A non '/admin/*' page with no admin_theme option. + 'page' => FALSE, + // A non '/admin/*' page with admin_theme set to TRUE. + 'page_true' => TRUE, + // A non '/admin/*' page with admin_theme set to FALSE. + 'page_false' => FALSE, + // An '/admin/*' page with no admin_theme option. + 'admin' => TRUE, + // An '/admin/*' page with admin_theme set to TRUE. + 'admin_true' => TRUE, + // An '/admin/*' page with admin_theme set to FALSE. + 'admin_false' => FALSE, + ]; + + foreach ($page_displays as $display_id => $expectation) { + $path = $this->config('views.view.test_page_display_admin_theme') + ->get("display.$display_id.display_options.path"); + $this->drupalGet($path); + $assertion = $expectation ? 'assertRaw' : 'assertNoRaw'; + $this->$assertion('seven/css/base/elements.css'); + } } /** diff --git a/core/modules/views/src/Tests/Update/AdminThemeOptionUpdateTest.php b/core/modules/views/src/Tests/Update/AdminThemeOptionUpdateTest.php index ed75184..92f672a 100644 --- a/core/modules/views/src/Tests/Update/AdminThemeOptionUpdateTest.php +++ b/core/modules/views/src/Tests/Update/AdminThemeOptionUpdateTest.php @@ -21,22 +21,24 @@ protected function setDatabaseDumpFiles() { } /** - * Tests the updating of views dependencies to image styles. + * Tests views_post_update_admin_theme(). + * + * @see views_post_update_admin_theme() */ public function testUpdateAdminThemeOption() { // Check that admin_theme option doesn't exist in 'content' view. $options = $this->config('views.view.content') ->get('display.page_1.display_options'); - $this->assertFalse(isset($options['admin_theme'])); + $this->assertFalse(array_key_exists('admin_theme', $options)); // Run updates. $this->runUpdates(); - // Check that admin_theme option was added in 'content' view and is TRUE. + // Check that admin_theme option was added in page display and is NULL. $options = $this->config('views.view.content') ->get('display.page_1.display_options'); - if ($this->assertTrue(isset($options['admin_theme']))) { - $this->assertFalse($options['admin_theme']); + if ($this->assertTrue(array_key_exists('admin_theme', $options))) { + $this->assertTrue($options['admin_theme'] === NULL); } } diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_page_display_admin_theme.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_page_display_admin_theme.yml new file mode 100644 index 0000000..953c26a --- /dev/null +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_page_display_admin_theme.yml @@ -0,0 +1,76 @@ +langcode: en +status: true +dependencies: { } +id: test_page_display_admin_theme +label: '' +module: views +description: '' +tag: '' +base_table: views_test_data +base_field: nid +core: '8' +display: + default: + display_options: + title: 'Test admin theme option' + defaults: + fields: false + pager: false + sorts: false + fields: + age: + field: age + id: age + relationship: none + table: views_test_data + plugin_id: numeric + display_plugin: default + display_title: Master + id: default + position: 0 + page: + display_options: + path: test_admin_theme/page + display_plugin: page + display_title: Page + id: page + position: 1 + page_true: + display_options: + path: test_admin_theme/page_true + admin_theme: true + display_plugin: page + display_title: Page + id: page_true + position: 2 + page_false: + display_options: + path: test_admin_theme/page_false + admin_theme: false + display_plugin: page + display_title: Page + id: page_false + position: 3 + admin: + display_options: + path: admin/test_admin_theme/admin + display_plugin: page + display_title: Page + id: admin + position: 4 + admin_true: + display_options: + path: admin/test_admin_theme/admin_true + admin_theme: true + display_plugin: page + display_title: Page + id: admin_true + position: 5 + admin_false: + display_options: + path: admin/test_admin_theme/admin_false + admin_theme: false + display_plugin: page + display_title: Page + id: admin_false + position: 6 diff --git a/core/modules/views/views.post_update.php b/core/modules/views/views.post_update.php index c043277..075dd21 100644 --- a/core/modules/views/views.post_update.php +++ b/core/modules/views/views.post_update.php @@ -213,7 +213,7 @@ function views_post_update_admin_theme() { // Deal only with page displays. if ($display['display_plugin'] == 'page') { $trail = "display.$display_id.display_options.admin_theme"; - $view->set($trail, FALSE)->save(); + $view->set($trail, NULL)->save(); } } }