function IconDefinition::getRenderable

Get the icon renderable element array.

Shortcut to use icon element quickly without check if the icon id is valid, then the element will simply be empty.

Parameters

string $icon_full_id: The id of the icon including the pack.

array $settings: Settings to pass to the renderable for context. Can be indexed by the icon pack id for lookup.

Return value

array|null The icon renderable.

Overrides IconDefinitionInterface::getRenderable

1 call to IconDefinition::getRenderable()
IconDefinitionTest::testGetRenderable in core/tests/Drupal/Tests/Core/Theme/Icon/IconDefinitionTest.php
Test the IconDefinition::getRenderable method.

File

core/lib/Drupal/Core/Theme/Icon/IconDefinition.php, line 103

Class

IconDefinition
Handle an icon definition.

Namespace

Drupal\Core\Theme\Icon

Code

public static function getRenderable(string $icon_full_id, array $settings = []) : ?array {
  if (!($icon_data = self::getIconDataFromId($icon_full_id))) {
    return NULL;
  }
  if (isset($settings[$icon_data['pack_id']])) {
    $settings = $settings[$icon_data['pack_id']];
  }
  return [
    '#type' => 'icon',
    '#pack_id' => $icon_data['pack_id'],
    '#icon_id' => $icon_data['icon_id'],
    '#settings' => $settings,
  ];
}

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