Version 1
[yaffs-website] / web / core / modules / filter / tests / filter_test / src / Plugin / Filter / FilterTestPlaceholders.php
1 <?php
2
3 namespace Drupal\filter_test\Plugin\Filter;
4
5 use Drupal\filter\FilterProcessResult;
6 use Drupal\filter\Plugin\FilterBase;
7
8 /**
9  * Provides a test filter to use placeholders.
10  *
11  * @Filter(
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
16  * )
17  */
18 class FilterTestPlaceholders extends FilterBase {
19
20   /**
21    * {@inheritdoc}
22    */
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>');
27     return $result;
28   }
29
30   /**
31    * #lazy_builder callback; builds a render array containing the dynamic thing.
32    *
33    * @param string $thing
34    *   A "thing" string.
35    *
36    * @return array
37    *   A renderable array.
38    */
39   public static function renderDynamicThing($thing) {
40     return [
41       '#markup' => format_string('This is a dynamic @thing.', ['@thing' => $thing]),
42     ];
43   }
44
45 }