class IconSelectExtension in Icon Select 8
Twig extension for icon rendering.
Hierarchy
- class \Drupal\icon_select\Twig\Extension\IconSelectExtension extends \Drupal\icon_select\Twig\Extension\Twig_Extension
Expanded class hierarchy of IconSelectExtension
1 string reference to 'IconSelectExtension'
1 service uses IconSelectExtension
File
- src/
Twig/ Extension/ IconSelectExtension.php, line 10
Namespace
Drupal\icon_select\Twig\ExtensionView source
class IconSelectExtension extends \Twig_Extension {
/**
* {@inheritdoc}
*/
public function getFunctions() {
return [
new \Twig_SimpleFunction('svg_icon', [
$this,
'iconSelectRender',
]),
];
}
/**
* {@inheritdoc}
*/
public function getName() {
return 'icon_select';
}
/**
* Returns an icon for a symbol id.
*
* @return array
* A render array of an icon.
*/
public function iconSelectRender($symbol_id, $classes = []) {
/** @var \Drupal\Core\Template\Attribute $attributes */
$attributes = new Attribute();
// Prepare classes.
$attributes
->addClass('icon', 'icon--' . $symbol_id);
$attributes
->addClass($classes);
$build = [
'#theme' => 'icon_select_svg_icon',
'#attributes' => $attributes,
'#symbol_id' => $symbol_id,
];
return $build;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
IconSelectExtension:: |
public | function | ||
IconSelectExtension:: |
public | function | ||
IconSelectExtension:: |
public | function | Returns an icon for a symbol id. |