Skip to content
Snippets Groups Projects
Verified Commit 4dbf3f46 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2719797 by claudiu.cristea, dww, pfrenssen, smustgrave, saurabh-2k17,...

Issue #2719797 by claudiu.cristea, dww, pfrenssen, smustgrave, saurabh-2k17, esolitos, swentel, sulfikar_s, lauriii, ayushmishra206, rajneeshb, aleevas, fago, Daniel Korte, snehalgaikwad, xjm, Ruchi Joshi, alexpott, arunkumark, mitthukumawat, gaurav-mathur, gayatri chahar, heni_deepak, yoroy, dawehner, jungle, kristiaanvandeneynde, Lendude, benjifisher, quietone, Bojhan, catch: New option for Views page displays to use the admin theme
parent 100aaec1
No related branches found
No related tags found
28 merge requests!54479.5.x SF update,!5014Issue #3071143: Table Render Array Example Is Incorrect,!4868Issue #1428520: Improve menu parent link selection,!4289Issue #1344552 by marcingy, Niklas Fiekas, Ravi.J, aleevas, Eduardo Morales...,!4114Issue #2707291: Disable body-level scrolling when a dialog is open as a modal,!4100Issue #3249600: Add support for PHP 8.1 Enums as allowed values for list_* data types,!3630Issue #2815301 by Chi, DanielVeza, kostyashupenko, smustgrave: Allow to create...,!3600Issue #3344629: Passing null to parameter #1 ($haystack) of type string is deprecated,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1591Issue #3199697: Add JSON:API Translation experimental module,!1484Exposed filters get values from URL when Ajax is on,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1162Issue #3100350: Unable to save '/' root path alias,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!925Issue #2339235: Remove taxonomy hard dependency on node module,!877Issue #2708101: Default value for link text is not saved,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!844Resolve #3036010 "Updaters",!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
......@@ -68,6 +68,10 @@ views.display.page:
menu_name:
type: string
label: 'Menu name'
use_admin_theme:
type: boolean
nullable: true
label: 'Use the administration theme when rendering the view page'
views.display.block:
type: views_display
......
......@@ -105,6 +105,10 @@ protected function getRoute($view_id, $display_id) {
// Explicitly set HTML as the format for Page displays.
$route->setRequirement('_format', 'html');
if ($this->getOption('use_admin_theme')) {
$route->setOption('_admin_route', TRUE);
}
return $route;
}
......@@ -244,6 +248,26 @@ public function optionsSummary(&$categories, &$options) {
$options['menu']['setting'] = $this->t('Parent menu link');
$options['menu']['links']['tab_options'] = $this->t('Change settings for the parent menu');
}
// If the display path starts with 'admin/' the page will be rendered with
// the Administration theme regardless of the 'use_admin_theme' option
// therefore, we need to set the summary message to reflect this.
if (str_starts_with($this->getOption('path') ?? '', 'admin/')) {
$admin_theme_text = $this->t('Yes (admin path)');
}
elseif ($this->getOption('use_admin_theme')) {
$admin_theme_text = $this->t('Yes');
}
else {
$admin_theme_text = $this->t('No');
}
$options['use_admin_theme'] = [
'category' => 'page',
'title' => $this->t('Administration theme'),
'value' => $admin_theme_text,
'desc' => $this->t('Use the administration theme when rendering this display.'),
];
}
/**
......@@ -445,6 +469,20 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
],
];
break;
case 'use_admin_theme':
$form['#title'] .= $this->t('Administration theme');
$form['use_admin_theme'] = [
'#type' => 'checkbox',
'#title' => $this->t('Use the administration theme'),
'#default_value' => $this->getOption('use_admin_theme'),
];
if (str_starts_with($this->getOption('path') ?? '', 'admin/')) {
$form['use_admin_theme']['#description'] = $this->t('Paths starting with "@admin" always use the administration theme.', ['@admin' => 'admin/']);
$form['use_admin_theme']['#default_value'] = TRUE;
$form['use_admin_theme']['#attributes'] = ['disabled' => 'disabled'];
}
break;
}
}
......@@ -495,6 +533,16 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) {
case 'tab_options':
$this->setOption('tab_options', $form_state->getValue('tab_options'));
break;
case 'use_admin_theme':
if ($form_state->getValue('use_admin_theme')) {
$this->setOption('use_admin_theme', $form_state->getValue('use_admin_theme'));
}
else {
unset($this->options['use_admin_theme']);
unset($this->display['display_options']['use_admin_theme']);
}
break;
}
}
......
......@@ -147,6 +147,37 @@ public function testPagePaths() {
$this->assertPagePath('☺');
}
/**
* Tests the 'use_admin_theme' page display option.
*/
public function testAdminTheme(): void {
$account = $this->drupalCreateUser(['view the administration theme']);
$this->drupalLogin($account);
// Use distinct default and administrative themes for this test.
/** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */
$theme_handler = $this->container->get('theme_handler');
/** @var \Drupal\Core\Extension\ThemeInstallerInterface $theme_installer */
$theme_installer = $this->container->get('theme_installer');
$theme_installer->install(['claro']);
$this->container->get('config.factory')
->getEditable('system.theme')
->set('admin', 'claro')
->set('default', 'stable')
->save();
$theme_handler->refreshInfo();
// Check that the page has been served with the default theme.
$this->drupalGet('test_page_display_200');
$this->assertSession()->responseNotContains('core/themes/claro/css/base/elements.css');
$view = $this->config('views.view.test_page_display');
$view->set('display.page_3.display_options.use_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->assertSession()->responseContains('core/themes/claro/css/base/elements.css');
}
/**
* Tests that we can successfully change a view page display path.
*
......
......@@ -4,6 +4,7 @@
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
/**
......@@ -15,6 +16,7 @@
class DisplayPathTest extends UITestBase {
use AssertPageCacheContextsAndTagsTrait;
use SchemaCheckTestTrait;
/**
* {@inheritdoc}
......@@ -286,4 +288,56 @@ public function testDefaultMenuTabRegression() {
$this->assertSession()->statusCodeEquals(200);
}
/**
* Tests the "Use the administration theme" configuration.
*
* @see \Drupal\Tests\views\Functional\Plugin\DisplayPageWebTest::testAdminTheme
*/
public function testUseAdminTheme(): void {
$this->drupalGet('admin/structure/views/view/test_view');
// Add a new page display.
$this->submitForm([], 'Add Page');
$this->assertSession()->pageTextContains('No path is set');
$this->assertSession()->pageTextContains('Administration theme: No');
// Test with a path starting with "/admin".
$admin_path = 'admin/test_admin_path';
$this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/path');
$this->submitForm(['path' => $admin_path], 'Apply');
$this->assertSession()->pageTextContains('/' . $admin_path);
$this->assertSession()->pageTextContains('Administration theme: Yes (admin path)');
$this->submitForm([], 'Save');
$this->assertConfigSchemaByName('views.view.test_view');
$display_options = $this->config('views.view.test_view')->get('display.page_1.display_options');
$this->assertArrayNotHasKey('use_admin_theme', $display_options);
$this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/use_admin_theme');
$this->assertSession()->elementExists('css', 'input[name="use_admin_theme"][disabled="disabled"][checked="checked"]');
// Test with a non-administration path.
$non_admin_path = 'kittens';
$this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/path');
$this->submitForm(['path' => $non_admin_path], 'Apply');
$this->assertSession()->pageTextContains('/' . $non_admin_path);
$this->assertSession()->pageTextContains('Administration theme: No');
$this->submitForm([], 'Save');
$this->assertConfigSchemaByName('views.view.test_view');
$display_options = $this->config('views.view.test_view')->get('display.page_1.display_options');
$this->assertArrayNotHasKey('use_admin_theme', $display_options);
// Enable administration theme.
$this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/use_admin_theme');
$this->submitForm(['use_admin_theme' => TRUE], 'Apply');
$this->assertSession()->pageTextContains('Administration theme: Yes');
$this->submitForm([], 'Save');
$this->assertConfigSchemaByName('views.view.test_view');
$display_options = $this->config('views.view.test_view')->get('display.page_1.display_options');
$this->assertArrayHasKey('use_admin_theme', $display_options);
$this->assertTrue($display_options['use_admin_theme']);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment