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'
1 service uses TwigExtension
File
- src/
Template/ TwigExtension.php, line 10
Namespace
Drupal\ui_patterns\TemplateView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TwigExtension:: |
public | function | ||
TwigExtension:: |
public | function | ||
TwigExtension:: |
public | function | Render given pattern. | |
TwigExtension:: |
public | function | Render given pattern. |