You are here

class TwigExtension in UI Patterns 8

Class UiPatternsTwigExtension.

@package Drupal\ui_patterns\Template

Hierarchy

  • class \Drupal\ui_patterns\Template\TwigExtension extends \Drupal\ui_patterns\Template\Twig_Extension

Expanded class hierarchy of TwigExtension

1 string reference to 'TwigExtension'
ui_patterns.services.yml in ./ui_patterns.services.yml
ui_patterns.services.yml
1 service uses TwigExtension
ui_patterns.twig.extension in ./ui_patterns.services.yml
Drupal\ui_patterns\Template\TwigExtension

File

src/Template/TwigExtension.php, line 10

Namespace

Drupal\ui_patterns\Template
View source
class TwigExtension extends \Twig_Extension {

  /**
   * {@inheritdoc}
   */
  public function getName() {
    return 'ui_patterns';
  }

  /**
   * {@inheritdoc}
   */
  public function getFunctions() {
    return [
      new \Twig_SimpleFunction('pattern', [
        $this,
        'renderPattern',
      ]),
      new \Twig_SimpleFunction('pattern_preview', [
        $this,
        'renderPatternPreview',
      ]),
    ];
  }

  /**
   * Render given pattern.
   *
   * @param string $id
   *   Pattern ID.
   * @param array $fields
   *   Pattern fields.
   * @param string $variant
   *   Variant name.
   *
   * @return array
   *   Pattern render array.
   *
   * @see \Drupal\ui_patterns\Element\Pattern
   */
  public function renderPattern($id, array $fields = [], $variant = "") {
    return [
      '#type' => 'pattern',
      '#id' => $id,
      '#fields' => $fields,
      '#variant' => $variant,
    ];
  }

  /**
   * Render given pattern.
   *
   * @param string $id
   *   Pattern ID.
   * @param string $variant
   *   Variant name.
   *
   * @return array
   *   Pattern render array.
   *
   * @see \Drupal\ui_patterns\Element\Pattern
   */
  public function renderPatternPreview($id, $variant = "") {
    return [
      '#type' => 'pattern_preview',
      '#id' => $id,
      '#variant' => $variant,
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TwigExtension::getFunctions public function
TwigExtension::getName public function
TwigExtension::renderPattern public function Render given pattern.
TwigExtension::renderPatternPreview public function Render given pattern.