You are here

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'
icon_select.services.yml in ./icon_select.services.yml
icon_select.services.yml
1 service uses IconSelectExtension
icon_select.twig.extension in ./icon_select.services.yml
Drupal\icon_select\Twig\Extension\IconSelectExtension

File

src/Twig/Extension/IconSelectExtension.php, line 10

Namespace

Drupal\icon_select\Twig\Extension
View 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

Namesort descending Modifiers Type Description Overrides
IconSelectExtension::getFunctions public function
IconSelectExtension::getName public function
IconSelectExtension::iconSelectRender public function Returns an icon for a symbol id.