function SvgExtractor::discoverIcons

Get a list of all the icons discovered by this extractor.

The icons must be provided as an associative array keyed by the icon id with values used to load the icon: source and group.

Return value

array List of icons that are found by this extractor. Keyed by icon full id.

Overrides IconExtractorInterface::discoverIcons

File

core/lib/Drupal/Core/Theme/Plugin/IconExtractor/SvgExtractor.php, line 39

Class

SvgExtractor
Plugin implementation of the icon_extractor.

Namespace

Drupal\Core\Theme\Plugin\IconExtractor

Code

public function discoverIcons() : array {
  // Check is included in getFilesFromSources(), but we need to disallow
  // remote sources before.
  $this->checkRequiredConfigSources();
  $this->configuration['config']['sources'] = array_filter($this->configuration['config']['sources'], function ($source) {
    return empty(parse_url($source, PHP_URL_SCHEME));
  });
  if (empty($this->configuration['config']['sources'])) {
    return [];
  }
  $files = $this->getFilesFromSources();
  if (empty($files)) {
    return [];
  }
  $icons = [];
  foreach ($files as $file) {
    if (!isset($file['absolute_path']) || empty($file['absolute_path'])) {
      continue;
    }
    $id = IconDefinition::createIconId($this->configuration['id'], $file['icon_id']);
    $icons[$id] = [
      'absolute_path' => $file['absolute_path'],
      'source' => $file['source'],
      'group' => $file['group'] ?? NULL,
    ];
  }
  return $icons;
}

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