Skip to content
Snippets Groups Projects
Verified Commit 4b835fad 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

(cherry picked from commit 4add05d0)
parent 28352d32
No related branches found
No related tags found
26 merge requests!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4,!10602Issue #3438769 by vinmayiswamy, antonnavi, michelle, amateescu: Sub workspace does not clear,!10301Issue #3469309 by mstrelan, smustgrave, moshe weitzman: Use one-time login...,!10187Issue #3487488 by dakwamine: ExtensionMimeTypeGuesser::guessMimeType must support file names with "0" (zero) like foo.0.zip,!9944Issue #3483353: Consider making the createCopy config action optionally fail...,!9929Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9787Resolve issue 3479427 - bootstrap barrio issue under Windows,!9742Issue #3463908 by catch, quietone: Split OptionsFieldUiTest into two,!9526Issue #3458177 by mondrake, catch, quietone, godotislate, longwave, larowlan,...,!8738Issue #3424162 by camilledavis, dineshkumarbollu, smustgrave: Claro...,!8704Make greek characters available in ckeditor5,!8597Draft: Issue #3442259 by catch, quietone, dww: Reduce time of Migrate Upgrade tests...,!8533Issue #3446962 by kim.pepper: Remove incorrectly added...,!8517Issue #3443748 by NexusNovaz, smustgrave: Testcase creates false positive,!8325Update file Sort.php,!8095Expose document root on install,!7930Resolve #3427374 "Taxonomytid viewsargumentdefault plugin",!7627Issue #3439440 by nicxvan, Binoli Lalani, longwave: Remove country support from DateFormatter,!7445Issue #3440169: When using drupalGet(), provide an associative array for $headers,!7401#3271894 Fix documented StreamWrapperInterface return types for realpath() and dirname(),!7384Add constraints to system.advisories,!7078Issue #3320569 by Spokje, mondrake, smustgrave, longwave, quietone, Lendude,...,!6622Issue #2559833 by piggito, mohit_aghera, larowlan, guptahemant, vakulrai,...,!6502Draft: Resolve #2938524 "Plach testing issue",!38582585169-10.1.x,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key
Pipeline #122064 failed
......@@ -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