class IconsTwigExtension
Twig extension for icon.
@internal
Hierarchy
- class \Twig\Extension\AbstractExtension implements \Twig\Extension\ExtensionInterface
- class \Drupal\Core\Template\IconsTwigExtension extends \Twig\Extension\AbstractExtension
Expanded class hierarchy of IconsTwigExtension
File
-
core/
lib/ Drupal/ Core/ Template/ IconsTwigExtension.php, line 15
Namespace
Drupal\Core\TemplateView source
final class IconsTwigExtension extends AbstractExtension {
/**
* {@inheritdoc}
*/
public function getFunctions() : array {
return [
new TwigFunction('icon', [
$this,
'getIconRenderable',
]),
];
}
/**
* Get an icon renderable array.
*
* @param string|null $pack_id
* The icon set ID.
* @param string|null $icon_id
* The icon ID.
* @param array|null $settings
* An array of settings for the icon.
*
* @return array
* The icon renderable.
*/
public function getIconRenderable(?string $pack_id, ?string $icon_id, ?array $settings = []) : array {
if (!$pack_id || !$icon_id) {
return [];
}
return [
'#type' => 'icon',
'#pack_id' => $pack_id,
'#icon_id' => $icon_id,
'#settings' => $settings,
];
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
AbstractExtension::getFilters | public | function | Returns a list of filters to add to the existing list. | Overrides ExtensionInterface::getFilters | 4 |
AbstractExtension::getNodeVisitors | public | function | Returns the node visitor instances to add to the existing list. | Overrides ExtensionInterface::getNodeVisitors | 9 |
AbstractExtension::getOperators | public | function | Returns a list of operators to add to the existing list. | Overrides ExtensionInterface::getOperators | 1 |
AbstractExtension::getTests | public | function | Returns a list of tests to add to the existing list. | Overrides ExtensionInterface::getTests | 2 |
AbstractExtension::getTokenParsers | public | function | Returns the token parser instances to add to the existing list. | Overrides ExtensionInterface::getTokenParsers | 5 |
IconsTwigExtension::getFunctions | public | function | Returns a list of functions to add to the existing list. | Overrides AbstractExtension::getFunctions | |
IconsTwigExtension::getIconRenderable | public | function | Get an icon renderable array. |