You are here

public function IconBasePluginManager::__construct in Icon API 8

Base plugin manager for Icon plugin managers.

The "container.namespaces" service does not contain theme namespaces since themes are not registered in the container. To allow themes to be able to participate in these plugins, the normal "namespaces" provided must be appending with the missing autoloader prefixes of the themes.

Parameters

\Traversable $namespaces: An object that implements \Traversable which contains the root paths keyed by the corresponding namespace to look for plugin implementations.

\Drupal\Core\Cache\CacheBackendInterface $cache_backend: Cache backend instance to use.

\Drupal\Core\Extension\ModuleHandlerInterface $module_handler: The module handler to invoke the alter hook with.

\Drupal\Core\Extension\ThemeHandlerInterface $theme_handler: The theme manager used to invoke the alter hook with.

\Drupal\Core\Theme\ThemeManagerInterface $theme_manager: The theme manager used to invoke the alter hook with.

string|null $plugin_interface: (optional) The interface each plugin should implement.

string $plugin_definition_annotation_name: (optional) The name of the annotation that contains the plugin definition. Defaults to 'Drupal\Component\Annotation\Plugin'.

Overrides DefaultPluginManager::__construct

3 calls to IconBasePluginManager::__construct()
IconProviderManager::__construct in src/IconProviderManager.php
Constructs a new \Drupal\icon\IconProviderManager object.
IconRendererManager::__construct in src/IconRendererManager.php
Constructs a new \Drupal\icon\IconRendererManager object.
IconSetManager::__construct in src/IconSetManager.php
Constructs a new \Drupal\icon\IconSetManager object.
3 methods override IconBasePluginManager::__construct()
IconProviderManager::__construct in src/IconProviderManager.php
Constructs a new \Drupal\icon\IconProviderManager object.
IconRendererManager::__construct in src/IconRendererManager.php
Constructs a new \Drupal\icon\IconRendererManager object.
IconSetManager::__construct in src/IconSetManager.php
Constructs a new \Drupal\icon\IconSetManager object.

File

src/IconBasePluginManager.php, line 56

Class

IconBasePluginManager

Namespace

Drupal\icon

Code

public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, ThemeManagerInterface $theme_manager, $plugin_interface = NULL, $plugin_definition_annotation_name = 'Drupal\\Component\\Annotation\\Plugin') {

  /** @var \Composer\Autoload\ClassLoader $class_loader */
  $class_loader = \Drupal::service('class_loader');

  /** @var \ArrayObject $namespaces */
  $ns = $namespaces
    ->getArrayCopy();
  foreach ($class_loader
    ->getPrefixesPsr4() as $prefix => $paths) {

    // Remove trailing path separators.
    $prefix = trim($prefix, '\\');

    // Remove the DRUPAL_ROOT prefix.
    $path = str_replace(\Drupal::root() . '/', '', reset($paths));

    // Only add missing contrib theme namespaces.
    if (preg_match('/^(core|vendor)/', $path) === 0 && !isset($namespaces[$prefix])) {
      $ns[$prefix] = $path;
    }
  }

  // Replace the namespaces data.
  $namespaces
    ->exchangeArray($ns);

  // Construct the plugin manager now.
  parent::__construct('Plugin/Icon', $namespaces, $module_handler, $plugin_interface, $plugin_definition_annotation_name);

  // Set the theme handler and manager.
  $this->themeHandler = $theme_handler;
  $this->themeManager = $theme_manager;
}