function IconCollector::getIconFromExtractor

Returns the icon from an icon id and icon pack definition.

Parameters

string $icon_full_id: The icon full id as pack_id:icon_id.

array $definitions: The icon pack definitions.

Return value

\Drupal\Core\Theme\Icon\IconDefinitionInterface|null The icon loaded.

1 call to IconCollector::getIconFromExtractor()
IconCollector::resolveCacheMiss in core/lib/Drupal/Core/Theme/Icon/IconCollector.php
Resolves a cache miss.

File

core/lib/Drupal/Core/Theme/Icon/IconCollector.php, line 80

Class

IconCollector
A CacheCollector implementation for building icons info.

Namespace

Drupal\Core\Theme\Icon

Code

private function getIconFromExtractor(string $icon_full_id, array $definitions) : ?IconDefinitionInterface {
    $icon_data = IconDefinition::getIconDataFromId($icon_full_id);
    if (!isset($icon_data['pack_id'])) {
        return NULL;
    }
    $definition = $definitions[$icon_data['pack_id']] ?? NULL;
    if (NULL === $definition) {
        return NULL;
    }
    $icon_definition = $definition['icons'][$icon_full_id] ?? NULL;
    if (NULL === $icon_definition) {
        return NULL;
    }
    $icon_definition['icon_id'] = $icon_data['icon_id'];
    // Clean to data to reduce the array passed to createInstance().
    unset($definition['icons']);
    
    /** @var \Drupal\Core\Theme\Icon\IconExtractorInterface $extractor */
    $extractor = $this->iconPackExtractorManager
        ->createInstance($definition['extractor'], $definition);
    return $extractor->loadIcon($icon_definition);
}

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