class IconsTwigExtension

Twig extension for icon.

@internal

Hierarchy

Expanded class hierarchy of IconsTwigExtension

1 file declares its use of IconsTwigExtension
IconsTwigExtensionTest.php in core/tests/Drupal/Tests/Core/Theme/Icon/IconsTwigExtensionTest.php

File

core/lib/Drupal/Core/Template/IconsTwigExtension.php, line 15

Namespace

Drupal\Core\Template
View 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
IconsTwigExtension::getFunctions public function
IconsTwigExtension::getIconRenderable public function Get an icon renderable array.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.