class ProviderManager

Manages discovery and instantiation of Bootstrap CDN Providers.

Hierarchy

  • class \Drupal\bootstrap\Plugin\PluginManager extends \Drupal\Core\Plugin\DefaultPluginManager
    • class \Drupal\bootstrap\Plugin\ProviderManager implements \Drupal\Component\Plugin\FallbackPluginManagerInterface

Expanded class hierarchy of ProviderManager

Related topics

6 files declare their use of ProviderManager
CdnCustom.php in src/Plugin/Setting/Advanced/Cdn/CdnCustom.php
CdnProvider.php in src/Plugin/Setting/Advanced/Cdn/CdnProvider.php
CdnProviderBase.php in src/Plugin/Setting/Advanced/Cdn/CdnProviderBase.php
deprecated.php in ./deprecated.php
This contains deprecated functions that will be removed in a future release.
ProviderBase.php in src/Plugin/Provider/ProviderBase.php

... See full list

Namespace

Drupal\bootstrap\Plugin
Source
class ProviderManager extends PluginManager implements FallbackPluginManagerInterface {
  /**
   * The base file system path for CDN Providers.
   *
   * @var string
   */
  const FILE_PATH = 'public://bootstrap/provider';

  /**
   * The Broken CDN Provider.
   *
   * @var \Drupal\bootstrap\Plugin\Provider\Broken
   */
  protected static $broken;

  /**
   * Constructs a new \Drupal\bootstrap\Plugin\ProviderManager object.
   *
   * @param \Drupal\bootstrap\Theme $theme
   *   The theme to use for discovery.
   */
  public function __construct(Theme $theme) {
    parent::__construct($theme, 'Plugin/Provider', 'Drupal\bootstrap\Plugin\Provider\ProviderInterface', 'Drupal\bootstrap\Annotation\BootstrapProvider');
    $this->setCacheBackend(\Drupal::cache('discovery'), 'theme:' . $theme->getName() . ':provider', $this->getCacheTags());
  }

  /**
   * Retrieves a CDN Provider.
   *
   * @param string $provider
   *   Optional. The ID of the provider to load. If not set or an invalid
   *   provider was specified, the base provider will be returned.
   * @param array $configuration
   *   Optional. An array of configuration relevant to the plugin instance.
   *
   * @return \Drupal\bootstrap\Plugin\Provider\ProviderInterface
   *   A CDN Provider instance.
   */
  public function get($provider, array $configuration = []) {
    return $this->createInstance($provider, $configuration + ['theme' => $this->theme]);
  }

  /**
   * {@inheritdoc}
   */
  public function getFallbackPluginId($plugin_id, array $configuration = []) {
    return '_broken';
  }

  /**
   * {@inheritdoc}
   */
  public function processDefinition(&$definition, $plugin_id) {
    parent::processDefinition($definition, $plugin_id);
    /** @var \Drupal\bootstrap\Plugin\Provider\ProviderInterface $provider */
    $provider = new $definition['class'](['theme' => $this->theme], $plugin_id, $definition);
    $provider->processDefinition($definition, $plugin_id);
  }

  /**
   * Returns the Broken CDN Provider instance.
   *
   * @return \Drupal\bootstrap\Plugin\Provider\Broken
   *   The Broken CDN Provider.
   */
  public static function broken() {
    if (!isset(static::$broken)) {
      static::$broken = (new static(Bootstrap::getTheme()))->get('_broken');
    }
    return static::$broken;
  }

  /**
   * Loads a CDN Provider.
   *
   * @param \Drupal\bootstrap\Theme|string $theme
   *   Optional. A theme to associate with the provider. If not set, the
   *   active theme will be used.
   * @param string $provider
   *   Optional. The ID of the provider to load. If not set, the provider set
   *   on the supplied or active $theme will be used.
   * @param array $configuration
   *   Optional. An array of configuration relevant to the plugin instance.
   *
   * @return \Drupal\bootstrap\Plugin\Provider\ProviderInterface
   *   A CDN Provider instance.
   */
  public static function load($theme = NULL, $provider = NULL, array $configuration = []) {
    $theme = Bootstrap::getTheme($theme);
    return (new static($theme))->get(isset($provider) ? $provider : $theme->getSetting('cdn_provider'), $configuration + ['theme' => $theme]);
  }

}

Members

Contains filters are case sensitive
Name Modifiers Type Description
PluginManager::$theme protected property The current theme.
PluginManager::$themeHandler protected property The theme handler to check if theme exists.
PluginManager::$themeManager protected property The theme manager to invoke alter hooks.
PluginManager::alterDefinitions protected function
PluginManager::createInstance public function
PluginManager::getCacheTags public function Retrieves the cache tags used to invalidate caches.
PluginManager::getDefinitions public function
PluginManager::getDefinitionsLike public function Retrieves all definitions where the plugin ID matches a certain criteria.
PluginManager::providerExists protected function
ProviderManager::$broken protected static property The Broken CDN Provider.
ProviderManager::broken public static function Returns the Broken CDN Provider instance.
ProviderManager::FILE_PATH constant The base file system path for CDN Providers.
ProviderManager::get public function Retrieves a CDN Provider.
ProviderManager::getFallbackPluginId public function
ProviderManager::load public static function Loads a CDN Provider.
ProviderManager::processDefinition public function
ProviderManager::__construct public function Constructs a new \Drupal\bootstrap\Plugin\ProviderManager object. Overrides PluginManager::__construct