function SvgSpriteExtractor::extractIdsFromXml

Extract icon ID from XML.

Parameters

string $source: Local path or url to the svg file.

Return value

array A list of icons with keys:

  • icon_ids: array of icon Id found
  • attributes: Attribute object from the svg
1 call to SvgSpriteExtractor::extractIdsFromXml()
SvgSpriteExtractor::discoverIcons in core/lib/Drupal/Core/Theme/Plugin/IconExtractor/SvgSpriteExtractor.php
Get a list of all the icons discovered by this extractor.

File

core/lib/Drupal/Core/Theme/Plugin/IconExtractor/SvgSpriteExtractor.php, line 69

Class

SvgSpriteExtractor
Plugin implementation of the icon_extractor.

Namespace

Drupal\Core\Theme\Plugin\IconExtractor

Code

private function extractIdsFromXml(string $source) : array {
    if (!($content = $this->iconFinder
        ->getFileContents($source))) {
        return [];
    }
    libxml_use_internal_errors(TRUE);
    if (!($svg = simplexml_load_string((string) $content))) {
        // @todo do we need to log a warning with the xml error?
        return [];
    }
    return $this->extractIdsFromSymbols($svg->symbol) ?: $this->extractIdsFromSymbols($svg->defs->symbol ?? NULL);
}

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