You are here

InlineTemplate.php in Zircon Profile 8

Same filename and directory in other branches
  1. 8.0 core/lib/Drupal/Core/Render/Element/InlineTemplate.php

File

core/lib/Drupal/Core/Render/Element/InlineTemplate.php
View source
<?php

/**
 * @file
 * Contains \Drupal\Core\Render\Element\InlineTemplate.
 */
namespace Drupal\Core\Render\Element;


/**
 * Provides a render element where the user supplies an in-line Twig template.
 *
 * @RenderElement("inline_template")
 */
class InlineTemplate extends RenderElement {

  /**
   * {@inheritdoc}
   */
  public function getInfo() {
    $class = get_class($this);
    return array(
      '#pre_render' => array(
        array(
          $class,
          'preRenderInlineTemplate',
        ),
      ),
      '#template' => '',
      '#context' => array(),
    );
  }

  /**
   * Renders a twig string directly.
   *
   * @param array $element
   *
   * @return array
   */
  public static function preRenderInlineTemplate($element) {

    /** @var \Drupal\Core\Template\TwigEnvironment $environment */
    $environment = \Drupal::service('twig');
    $markup = $environment
      ->renderInline($element['#template'], $element['#context']);
    $element['#markup'] = $markup;
    return $element;
  }

}

Classes

Namesort descending Description
InlineTemplate Provides a render element where the user supplies an in-line Twig template.