cookie_blocking_libraries-1.0.x-dev/src/CookieImplementationPluginManager.php

src/CookieImplementationPluginManager.php
<?php

namespace Drupal\cookie_blocking_libraries;

use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;

/**
 * CookieBlockingLibrariesImplementation plugin manager.
 */
class CookieImplementationPluginManager extends DefaultPluginManager {

  /**
   * Constructs CookieImplementationPluginManager object.
   *
   * @param \Traversable $namespaces
   *   An object that implements \Traversable which contains the root paths
   *   keyed by the corresponding namespace to look for plugin implementations.
   * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
   *   Cache backend instance to use.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler to invoke the alter hook with.
   */
  public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
    parent::__construct(
      'Plugin/CookieBlockingLibrariesImplementation',
      $namespaces,
      $module_handler,
      'Drupal\cookie_blocking_libraries\CookieImplementationInterface',
      'Drupal\cookie_blocking_libraries\Annotation\CookieBlockingLibrariesImplementation'
    );
    $this->alterInfo('cookie_blocking_libraries_implementation_info');
    $this->setCacheBackend($cache_backend, 'cookie_blocking_libraries_implementation_plugins');
  }

  /**
   * Get a list of options to use in a Form API select element, for example.
   *
   * @return array
   *   The list of plugin labels keyed by the plugin ID.
   */
  public function getSelectOptions() {
    $options = [];
    foreach ($this->getDefinitions() as $definition) {
      $options[$definition['id']] = $definition['label'];
    }
    return $options;
  }

  /**
   * Get the enabled plugin.
   *
   * @return \Drupal\cookie_blocking_libraries\CookieImplementationInterface|null
   *   The plugin, if available.
   */
  public function getEnabledPlugin() {
    $enabled_plugin_id = \Drupal::config('cookie_blocking_libraries.implementation_settings')->get('enabled_plugins');
    if (empty($enabled_plugin_id)) {
      return NULL;
    }
    if (!$this->hasDefinition($enabled_plugin_id)) {
      return NULL;
    }
    return $this->createInstance($enabled_plugin_id);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc