Skip to content
Snippets Groups Projects
Commit eb5a842d authored by catch's avatar catch
Browse files

Issue #3463038 by longwave: Add helper method to generate HTML placeholders

parent 3219336f
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 #237181 canceled
......@@ -111,16 +111,13 @@ public function createPlaceholder(array $element) {
// Generate placeholder markup. Note that the only requirement is that this
// is unique markup that isn't easily guessable. The #lazy_builder callback
// and its arguments are put in the placeholder markup solely to simplify<<<
// and its arguments are put in the placeholder markup solely to simplify
// debugging.
$callback = $placeholder_render_array['#lazy_builder'][0];
$arguments = UrlHelper::buildQuery($placeholder_render_array['#lazy_builder'][1]);
$token = Crypt::hashBase64(serialize($placeholder_render_array));
$placeholder_markup = '<drupal-render-placeholder callback="' . Html::escape($callback) . '"';
if ($arguments !== '') {
$placeholder_markup .= ' arguments="' . Html::escape($arguments) . '"';
}
$placeholder_markup .= ' token="' . Html::escape($token) . '"></drupal-render-placeholder>';
$placeholder_markup = static::createPlaceholderTag('drupal-render-placeholder', [
'callback' => $placeholder_render_array['#lazy_builder'][0],
'arguments' => UrlHelper::buildQuery($placeholder_render_array['#lazy_builder'][1]),
'token' => Crypt::hashBase64(serialize($placeholder_render_array)),
]);
// Build the placeholder element to return.
$placeholder_element = [];
......@@ -129,4 +126,18 @@ public function createPlaceholder(array $element) {
return $placeholder_element;
}
/**
* {@inheritdoc}
*/
public static function createPlaceholderTag(string $tag, array $attributes): string {
$markup = "<$tag";
foreach ($attributes as $key => $value) {
if ($value !== '') {
$markup .= ' ' . $key . '="' . Html::escape($value) . '"';
}
}
$markup .= "></$tag>";
return $markup;
}
}
......@@ -62,4 +62,17 @@ public function shouldAutomaticallyPlaceholder(array $element);
*/
public function createPlaceholder(array $element);
/**
* Generates a placeholder HTML tag.
*
* @param string $tag
* The placeholder tag.
* @param array $attributes
* An array of key-value pairs to use as tag attributes.
*
* @return string
* The HTML placeholder.
*/
public static function createPlaceholderTag(string $tag, array $attributes): string;
}
......@@ -3,9 +3,9 @@
namespace Drupal\filter;
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Render\PlaceholderGenerator;
/**
* Used to return values from a text filter plugin's processing method.
......@@ -133,14 +133,11 @@ public function setProcessedText($processed_text) {
*/
public function createPlaceholder($callback, array $args) {
// Generate placeholder markup.
// @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) . '"';
if ($arguments !== '') {
$placeholder_markup .= ' arguments="' . Html::escape($arguments) . '"';
}
$placeholder_markup .= ' token="' . Html::escape($token) . '"></drupal-filter-placeholder>';
$placeholder_markup = PlaceholderGenerator::createPlaceholderTag('drupal-filter-placeholder', [
'callback' => $callback,
'arguments' => UrlHelper::buildQuery($args),
'token' => Crypt::hashBase64(serialize([$callback, $args])),
]);
// Add the placeholder attachment.
$this->addAttachments([
......
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