FilterProcessResult::createPlaceholder

public FilterProcessResult::createPlaceholder($callback, array $args)

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 133

Class

FilterProcessResult
Used to return values from a text filter plugin's processing method.

Namespace

Drupal\filter

Code

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;
}
doc_Drupal
2016-10-29 09:14:51
Comments
Leave a Comment

Please login to continue.