Skip to content
Snippets Groups Projects
Verified Commit dc89b84c authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3454196 by james.williams, longwave: Filter placeholders without...

Issue #3454196 by james.williams, longwave: Filter placeholders without arguments are not replaced when HTML corrector filter applied afterwards
parent cc32980f
No related branches found
No related tags found
18 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,!8736Update the Documention As per the Function uses.,!8513Issue #3453786: DefaultSelection should document why values for target_bundles NULL and [] behave as they do,!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,!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,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2062Issue #3246454: Add weekly granularity to views date sort,!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 #230909 canceled
......@@ -136,7 +136,11 @@ public function createPlaceholder($callback, array $args) {
// @see \Drupal\Core\Render\PlaceholderGenerator::createPlaceholder()
$arguments = UrlHelper::buildQuery($args);
$token = Crypt::hashBase64(serialize([$callback, $args]));
$placeholder_markup = '<drupal-filter-placeholder callback="' . Html::escape($callback) . '" arguments="' . Html::escape($arguments) . '" token="' . Html::escape($token) . '"></drupal-filter-placeholder>';
$placeholder_markup = '<drupal-filter-placeholder callback="' . Html::escape($callback) . '"';
if ($arguments !== '') {
$placeholder_markup .= ' arguments="' . Html::escape($arguments) . '"';
}
$placeholder_markup .= ' token="' . Html::escape($token) . '"></drupal-filter-placeholder>';
// Add the placeholder attachment.
$this->addAttachments([
......
......@@ -16,7 +16,7 @@
#[Filter(
id: "filter_test_placeholders",
title: new TranslatableMarkup("Testing filter"),
description: new TranslatableMarkup("Appends a placeholder to the content; associates #lazy_builder callback."),
description: new TranslatableMarkup("Appends placeholders to the content; associates #lazy_builder callbacks."),
type: FilterInterface::TYPE_TRANSFORM_REVERSIBLE
)]
class FilterTestPlaceholders extends FilterBase implements TrustedCallbackInterface {
......@@ -26,8 +26,9 @@ class FilterTestPlaceholders extends FilterBase implements TrustedCallbackInterf
*/
public function process($text, $langcode) {
$result = new FilterProcessResult($text);
$placeholder = $result->createPlaceholder('\Drupal\filter_test\Plugin\Filter\FilterTestPlaceholders::renderDynamicThing', ['llama']);
$result->setProcessedText($text . '<p>' . $placeholder . '</p>');
$placeholder_with_argument = $result->createPlaceholder('\Drupal\filter_test\Plugin\Filter\FilterTestPlaceholders::renderDynamicThing', ['llama']);
$placeholder_without_arguments = $result->createPlaceholder('\Drupal\filter_test\Plugin\Filter\FilterTestPlaceholders::renderStaticThing', []);
$result->setProcessedText($text . '<p>' . $placeholder_with_argument . '</p>' . '<p>' . $placeholder_without_arguments . '</p>');
return $result;
}
......@@ -46,11 +47,26 @@ public static function renderDynamicThing($thing) {
];
}
/**
* #lazy_builder callback; builds a render array.
*
* @return array
* A renderable array.
*/
public static function renderStaticThing(): array {
return [
'#markup' => 'This is a static llama.',
];
}
/**
* {@inheritdoc}
*/
public static function trustedCallbacks() {
return ['renderDynamicThing'];
return [
'renderDynamicThing',
'renderStaticThing',
];
}
}
......@@ -318,7 +318,7 @@ public function testProcessedTextElement(): void {
'user.permissions',
];
$this->assertEqualsCanonicalizing($expected_cache_contexts, $build['#cache']['contexts'], 'Expected cache contexts present.');
$expected_markup = '<p>Hello, world!</p><p>This is a dynamic llama.</p>';
$expected_markup = '<p>Hello, world!</p><p>This is a dynamic llama.</p><p>This is a static llama.</p>';
$this->assertSame($expected_markup, (string) $build['#markup'], 'Expected #lazy_builder callback has been applied.');
}
......
......@@ -58,7 +58,7 @@ protected function getExpectedNormalizedEntity() {
[
'value' => 'Cádiz is the oldest continuously inhabited city in Spain and a nice place to spend a Sunday with friends.',
'format' => 'my_text_format',
'processed' => '<p>Cádiz is the oldest continuously inhabited city in Spain and a nice place to spend a Sunday with friends.</p>' . "\n" . '<p>This is a dynamic llama.</p>',
'processed' => '<p>Cádiz is the oldest continuously inhabited city in Spain and a nice place to spend a Sunday with friends.</p>' . "\n" . '<p>This is a dynamic llama.</p><p>This is a static llama.</p>',
],
];
return $expected;
......
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