public function FilterProcessResult::createPlaceholder in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/filter/src/FilterProcessResult.php \Drupal\filter\FilterProcessResult::createPlaceholder()
Creates a placeholder.
This generates its own placeholder markup for one major reason: to not have FilterProcessResult depend on the Renderer service, because this is a value object. As a side-effect and added benefit, this makes it easier to distinguish placeholders for filtered text versus generic render system placeholders.
Parameters
string $callback: The #lazy_builder callback that will replace the placeholder with its eventual markup.
array $args: The arguments for the #lazy_builder callback.
Return value
string The placeholder markup.
File
- core/
modules/ filter/ src/ FilterProcessResult.php, line 139 - Contains \Drupal\filter\FilterProcessResult.
Class
- FilterProcessResult
- Used to return values from a text filter plugin's processing method.
Namespace
Drupal\filterCode
public function createPlaceholder($callback, array $args) {
// Generate placeholder markup.
// @see \Drupal\Core\Render\PlaceholderGenerator::createPlaceholder()
$arguments = UrlHelper::buildQuery($args);
$token = hash('crc32b', serialize([
$callback,
$args,
]));
$placeholder_markup = '<drupal-filter-placeholder callback="' . Html::escape($callback) . '" arguments="' . Html::escape($arguments) . '" token="' . Html::escape($token) . '"></drupal-filter-placeholder>';
// Add the placeholder attachment.
$this
->addAttachments([
'placeholders' => [
$placeholder_markup => [
'#lazy_builder' => [
$callback,
$args,
],
],
],
]);
// Return the placeholder markup, so that the filter wanting to use a
// placeholder can actually insert the placeholder markup where it needs the
// placeholder to be replaced.
return $placeholder_markup;
}