Added another front page space for Yaffs info. Added roave security for composer.
[yaffs-website] / web / core / lib / Drupal / Core / Render / Element / InlineTemplate.php
1 <?php
2
3 namespace Drupal\Core\Render\Element;
4
5 /**
6  * Provides a render element where the user supplies an in-line Twig template.
7  *
8  * Properties:
9  * - #template: The inline Twig template used to render the element.
10  * - #context: (array) The variables to substitute into the Twig template.
11  *   Each variable may be a string or a render array.
12  *
13  * Usage example:
14  * @code
15  * $build['hello']  = [
16  *   '#type' => 'inline_template',
17  *   '#template' => "{% trans %} Hello {% endtrans %} <strong>{{name}}</strong>",
18  *   '#context' => [
19  *     'name' => $name,
20  *   ]
21  * ];
22  * @endcode
23  *
24  * @RenderElement("inline_template")
25  */
26 class InlineTemplate extends RenderElement {
27
28   /**
29    * {@inheritdoc}
30    */
31   public function getInfo() {
32     $class = get_class($this);
33     return [
34       '#pre_render' => [
35         [$class, 'preRenderInlineTemplate'],
36       ],
37       '#template' => '',
38       '#context' => [],
39     ];
40   }
41
42   /**
43    * Renders a twig string directly.
44    *
45    * @param array $element
46    *
47    * @return array
48    */
49   public static function preRenderInlineTemplate($element) {
50     /** @var \Drupal\Core\Template\TwigEnvironment $environment */
51     $environment = \Drupal::service('twig');
52     $markup = $environment->renderInline($element['#template'], $element['#context']);
53     $element['#markup'] = $markup;
54     return $element;
55   }
56
57 }