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

Issue #2663316 by omkar.podey, jofitz, alexpott, shashank5563,...

Issue #2663316 by omkar.podey, jofitz, alexpott, shashank5563, samuel.mortenson, Andrej Galuf, djsagar, silverham, juliaschwarz, lauriii, super_romeo, gawaksh, smustgrave, sakthi_dev, Pavan B S, lammensj, Wim Leers, camerongreen, quietone: Broken title in modal dialog when title is a render array
parent d71f6de6
No related branches found
No related tags found
27 merge requests!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!9470[10.3.x-only-DO-NOT-MERGE]: #3331771 Fix file_get_contents(): Passing null to parameter,!8540Issue #3457061: Bootstrap Modal dialog Not closing after 10.3.0 Update,!8528Issue #3456871 by Tim Bozeman: Support NULL services,!8373Issue #3427374 by danflanagan8, Vighneshh: taxonomy_tid ViewsArgumentDefault...,!7526Expose roles in response,!7352Draft: Resolve #3203489 "Set filename as",!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2794Issue #3100732: Allow specifying `meta` data on JSON:API objects,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!877Issue #2708101: Default value for link text is not saved,!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
Pipeline #122126 canceled
......@@ -59,7 +59,7 @@ class OpenDialogCommand implements CommandInterface, CommandWithAttachedAssetsIn
*
* @param string $selector
* The selector of the dialog.
* @param string $title
* @param string|\Stringable|null $title
* The title of the dialog.
* @param string|array $content
* The content that will be placed in the dialog, either a render array
......@@ -72,8 +72,9 @@ class OpenDialogCommand implements CommandInterface, CommandWithAttachedAssetsIn
* on the content of the dialog. If left empty, the settings will be
* populated automatically from the current request.
*/
public function __construct($selector, $title, $content, array $dialog_options = [], $settings = NULL) {
public function __construct($selector, string|\Stringable|null $title, $content, array $dialog_options = [], $settings = NULL) {
$title = PlainTextOutput::renderFromHtml($title);
$dialog_options += ['title' => $title];
$this->selector = $selector;
$this->content = $content;
......
......@@ -17,7 +17,7 @@ class OpenModalDialogCommand extends OpenDialogCommand {
* until the modal has been completed. Drupal provides a built-in modal for
* this purpose, so no selector needs to be provided.
*
* @param string $title
* @param string|\Stringable|null $title
* The title of the dialog.
* @param string|array $content
* The content that will be placed in the dialog, either a render array
......@@ -30,7 +30,7 @@ class OpenModalDialogCommand extends OpenDialogCommand {
* on the content of the dialog. If left empty, the settings will be
* populated automatically from the current request.
*/
public function __construct($title, $content, array $dialog_options = [], $settings = NULL) {
public function __construct(string|\Stringable|null $title, $content, array $dialog_options = [], $settings = NULL) {
$dialog_options['modal'] = TRUE;
parent::__construct('#drupal-modal', $title, $content, $dialog_options, $settings);
}
......
......@@ -22,7 +22,7 @@ class OpenOffCanvasDialogCommand extends OpenDialogCommand {
* behaviors. Drupal provides a built-in off-canvas dialog for this purpose,
* so the selector is hard-coded in the call to the parent constructor.
*
* @param string $title
* @param string|\Stringable|null $title
* The title of the dialog.
* @param string|array $content
* The content that will be placed in the dialog, either a render array
......@@ -37,7 +37,7 @@ class OpenOffCanvasDialogCommand extends OpenDialogCommand {
* @param string $position
* (optional) The position to render the off-canvas dialog.
*/
public function __construct($title, $content, array $dialog_options = [], $settings = NULL, $position = 'side') {
public function __construct(string|\Stringable|null $title, $content, array $dialog_options = [], $settings = NULL, $position = 'side') {
parent::__construct('#drupal-off-canvas', $title, $content, $dialog_options, $settings);
$this->dialogOptions['modal'] = FALSE;
$this->dialogOptions['autoResize'] = FALSE;
......
......@@ -56,9 +56,8 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
$main_content['#attached']['library'][] = 'core/drupal.dialog.ajax';
$response->setAttachments($main_content['#attached']);
// Determine the title: use the title provided by the main content if any,
// otherwise get it from the routing information.
$title = $main_content['#title'] ?? $this->titleResolver->getTitle($request, $route_match->getRouteObject());
// Determine the title.
$title = $this->getTitleAsStringable($main_content, $request, $route_match);
// Determine the dialog options and the target for the OpenDialogCommand.
$options = $this->getDialogOptions($request);
......@@ -116,4 +115,36 @@ protected function getDialogOptions(Request $request): array {
return $request->request->all('dialogOptions');
}
/**
* Gets the title as a string or stringable object.
*
* Uses the title provided by the main content if any, otherwise gets it from
* the routing information.
*
* @param array $main_content
* The main content array.
* @param \Symfony\Component\HttpFoundation\Request $request
* The request.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*
* @return \Stringable|string|null
* The title as a string or stringable object.
*/
protected function getTitleAsStringable(array $main_content, Request $request, RouteMatchInterface $route_match): \Stringable|string|null {
$title = NULL;
if (array_key_exists('#title', $main_content)) {
if (is_array($main_content['#title'])) {
$title = $this->renderer->renderInIsolation($main_content['#title']);
}
else {
$title = $main_content['#title'];
}
}
elseif ($this->titleResolver->getTitle($request, $route_match->getRouteObject())) {
$title = $this->titleResolver->getTitle($request, $route_match->getRouteObject())->render();
}
return $title;
}
}
......@@ -26,8 +26,8 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
$main_content['#attached']['library'][] = 'core/drupal.dialog.ajax';
$response->setAttachments($main_content['#attached']);
// If the main content doesn't provide a title, use the title resolver.
$title = $main_content['#title'] ?? $this->titleResolver->getTitle($request, $route_match->getRouteObject());
// Determine the title.
$title = $this->getTitleAsStringable($main_content, $request, $route_match);
// Determine the dialog options for the OpenDialogCommand.
$options = $this->getDialogOptions($request);
......
......@@ -59,8 +59,8 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
$main_content['#attached']['library'][] = 'core/drupal.dialog.off_canvas';
$response->setAttachments($main_content['#attached']);
// If the main content doesn't provide a title, use the title resolver.
$title = $main_content['#title'] ?? $this->titleResolver->getTitle($request, $route_match->getRouteObject());
// Determine the title.
$title = $this->getTitleAsStringable($main_content, $request, $route_match);
// Determine the title: use the title provided by the main content if any,
// otherwise get it from the routing information.
......
......@@ -55,8 +55,8 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
$main_content['#attached']['library'][] = 'core/drupal.dialog.ajax';
$response->setAttachments($main_content['#attached']);
// If the main content doesn't provide a title, use the title resolver.
$title = $main_content['#title'] ?? $this->titleResolver->getTitle($request, $route_match->getRouteObject());
// Determine the title.
$title = $this->getTitleAsStringable($main_content, $request, $route_match);
// Determine the title: use the title provided by the main content if any,
// otherwise get it from the routing information.
......
......@@ -4,10 +4,11 @@
namespace Drupal\Tests\views\FunctionalJavascript\Plugin\views\Handler;
use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\field\Entity\FieldConfig;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\views\Tests\ViewTestData;
/**
......@@ -58,7 +59,7 @@ protected function setUp(): void {
// Disable automatic live preview to make the sequence of calls clearer.
\Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save();
$this->account = $this->drupalCreateUser(['administer views']);
$this->account = $this->drupalCreateUser(['administer views', 'access content overview']);
$this->drupalLogin($this->account);
NodeType::create([
......@@ -73,6 +74,44 @@ protected function setUp(): void {
])->save();
}
/**
* Tests custom text field modal title.
*/
public function testModalDialogTitle(): void {
$web_assert = $this->assertSession();
Node::create([
'title' => $this->randomString(),
'type' => 'page',
'body' => 'page',
])->save();
$base_path = \Drupal::request()->getBasePath();
$url = "$base_path/admin/structure/views/view/content";
$this->drupalGet($url);
$page = $this->getSession()->getPage();
// Open the 'Add fields dialog'.
$page->clickLink('views-add-field');
$web_assert->waitForField('name[views.nothing]');
// Select the custom text field.
$page->checkField('name[views.nothing]');
$page->find('css', '.ui-dialog .ui-dialog-buttonset')->pressButton('Add and configure fields');
$web_assert->waitForField('options[alter][text]');
$page->fillField('options[alter][text]', "{{ attach_library(\"core/drupal.dialog.ajax\") }}
<p><a class=\"use-ajax\" data-dialog-type=\"modal\" href=\"$base_path/admin/content\">Content link</a></p>");
$page->find('css', '.ui-dialog .ui-dialog-buttonset')->pressButton('Apply');
$web_assert->waitForText('Content: body (exposed)');
$web_assert->waitForButton('Save');
$page->pressButton('Save');
$web_assert->waitForText('The view Content has been saved.');
$web_assert->waitForButton('Update preview');
$page->pressButton('Update preview');
// Open the custom text link modal.
$this->assertNotNull($web_assert->waitForLink('Content link'));
$page->clickLink('Content link');
// Verify the modal title.
$web_assert->assertWaitOnAjaxRequest();
$this->assertEquals('Content', $web_assert->waitForElement('css', '.ui-dialog-title')->getText());
}
public function testFormatterChanging() {
$web_assert = $this->assertSession();
$url = '/admin/structure/views/view/test_field_body';
......
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