class IconExtractorWithFinder

Base class for icon_extractor plugins.

This is a wrapper for the IconFinder class to load icon files based on path or urls.

@internal This API is experimental.

Hierarchy

Expanded class hierarchy of IconExtractorWithFinder

4 files declare their use of IconExtractorWithFinder
PathExtractor.php in core/lib/Drupal/Core/Theme/Plugin/IconExtractor/PathExtractor.php
SvgExtractor.php in core/lib/Drupal/Core/Theme/Plugin/IconExtractor/SvgExtractor.php
SvgSpriteExtractor.php in core/lib/Drupal/Core/Theme/Plugin/IconExtractor/SvgSpriteExtractor.php
TestExtractorWithFinder.php in core/modules/system/tests/modules/icon_test/src/Plugin/IconExtractor/TestExtractorWithFinder.php

File

core/lib/Drupal/Core/Theme/Icon/IconExtractorWithFinder.php, line 22

Namespace

Drupal\Core\Theme\Icon
View source
abstract class IconExtractorWithFinder extends IconExtractorBase implements IconExtractorWithFinderInterface, PluginWithFormsInterface, ContainerFactoryPluginInterface {
    use PluginWithFormsTrait;
    
    /**
     * Constructs a IconExtractorWithFinder object.
     *
     * @param array $configuration
     *   A configuration array containing information about the plugin instance.
     * @param string $plugin_id
     *   The plugin_id for the plugin instance.
     * @param mixed $plugin_definition
     *   The plugin implementation definition.
     * @param \Drupal\Core\Theme\Icon\IconFinder $iconFinder
     *   The icons finder service.
     */
    public function __construct(array $configuration, $plugin_id, $plugin_definition, IconFinder $iconFinder) {
        parent::__construct($configuration, $plugin_id, $plugin_definition);
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) : self {
        return new static($configuration, $plugin_id, $plugin_definition, $container->get(IconFinder::class));
    }
    
    /**
     * {@inheritdoc}
     */
    public function getFilesFromSources() : array {
        $this->checkRequiredConfigSources();
        if (!isset($this->configuration['relative_path'])) {
            throw new IconPackConfigErrorException(sprintf('Empty relative path for extractor %s.', $this->getPluginId()));
        }
        return $this->iconFinder
            ->getFilesFromSources($this->configuration['config']['sources'], $this->configuration['relative_path']);
    }
    
    /**
     * Check the required `config > sources` value from definition.
     *
     * @throws \Drupal\Core\Theme\Icon\Exception\IconPackConfigErrorException
     *   If the config:sources value in definition is not set or not valid.
     */
    protected function checkRequiredConfigSources() : void {
        if (!isset($this->configuration['config']['sources']) || empty($this->configuration['config']['sources']) || !is_array($this->configuration['config']['sources'])) {
            throw new IconPackConfigErrorException(sprintf('Missing or invalid `config: sources` in your definition, extractor %s requires this value as array.', $this->getPluginId()));
        }
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
IconExtractorBase::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm
IconExtractorBase::createIcon public function Create the icon definition from an extractor plugin. Overrides IconExtractorInterface::createIcon
IconExtractorBase::DEFINITION_REMOVE private constant
IconExtractorBase::description public function Returns the translated plugin description. Overrides IconExtractorInterface::description
IconExtractorBase::label public function Returns the translated plugin label. Overrides IconExtractorInterface::label
IconExtractorBase::loadIcon public function Load an icon object. Overrides IconExtractorInterface::loadIcon 1
IconExtractorBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
IconExtractorBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
IconExtractorInterface::discoverIcons public function Get a list of all the icons discovered by this extractor. 5
IconExtractorWithFinder::checkRequiredConfigSources protected function Check the required `config > sources` value from definition.
IconExtractorWithFinder::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
IconExtractorWithFinder::getFilesFromSources public function Create files data from sources config. Overrides IconExtractorWithFinderInterface::getFilesFromSources
IconExtractorWithFinder::__construct public function Constructs a IconExtractorWithFinder object. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin.
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin ID.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Gets the plugin ID of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable Deprecated public function Determines if the plugin is configurable.
PluginWithFormsTrait::getFormClass public function Implements \Drupal\Core\Plugin\PluginWithFormsInterface::getFormClass().
PluginWithFormsTrait::hasFormClass public function Implements \Drupal\Core\Plugin\PluginWithFormsInterface::hasFormClass().

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