entity_agree-2.0.x-dev/src/AgreementHandlerPluginManager.php
src/AgreementHandlerPluginManager.php
<?php namespace Drupal\entity_agree; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; /** * Plugin manager for agreement handlers. */ class AgreementHandlerPluginManager extends DefaultPluginManager { /** * Constructs a new AliasType manager instance. * * @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/entity_agree/AgreementHandler', $namespaces, $module_handler, 'Drupal\entity_agree\AgreementHandlerInterface', 'Drupal\entity_agree\Annotation\AgreementHandler'); $this->alterInfo('entity_agree_handler'); $this->setCacheBackend($cache_backend, 'entity_agree_handlers'); } /** * Get the options for selecting an agreement handler plugin. * * @param array $exclude * Plugin IDs to exclude from options. Optional, defaults to no plugin * excluded. * * @return array * The options for selecting an agreement handler plugin. */ public function getPluginSelectionOptions(array $exclude = []) { $options = []; foreach ($this->getDefinitions() as $definition) { if (in_array($definition['id'], $exclude)) { continue; } if ($definition['category']) { $options[(string) $definition['category']][$definition['id']] = $definition['label']; } else { $options[$definition['id']] = $definition['label']; } } return $options; } }