function FilterProcessResult::createPlaceholder
Same name in other branches
- 9 core/modules/filter/src/FilterProcessResult.php \Drupal\filter\FilterProcessResult::createPlaceholder()
- 8.9.x core/modules/filter/src/FilterProcessResult.php \Drupal\filter\FilterProcessResult::createPlaceholder()
- 10 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 134
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.
$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([
'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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.