3 namespace Drupal\filter_test\Plugin\Filter;
5 use Drupal\filter\FilterProcessResult;
6 use Drupal\filter\Plugin\FilterBase;
9 * Provides a test filter to use placeholders.
12 * id = "filter_test_placeholders",
13 * title = @Translation("Testing filter"),
14 * description = @Translation("Appends a placeholder to the content; associates #lazy_builder callback."),
15 * type = Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_REVERSIBLE
18 class FilterTestPlaceholders extends FilterBase {
23 public function process($text, $langcode) {
24 $result = new FilterProcessResult($text);
25 $placeholder = $result->createPlaceholder('\Drupal\filter_test\Plugin\Filter\FilterTestPlaceholders::renderDynamicThing', ['llama']);
26 $result->setProcessedText($text . '<p>' . $placeholder . '</p>');
31 * #lazy_builder callback; builds a render array containing the dynamic thing.
33 * @param string $thing
39 public static function renderDynamicThing($thing) {
41 '#markup' => format_string('This is a dynamic @thing.', ['@thing' => $thing]),