class GroupContentEnablerManager in Group 8
Manages GroupContentEnabler plugin implementations.
Hierarchy
- class \Drupal\Component\Plugin\PluginManagerBase implements PluginManagerInterface uses DiscoveryTrait
- class \Drupal\Core\Plugin\DefaultPluginManager implements CachedDiscoveryInterface, PluginManagerInterface, CacheableDependencyInterface uses DiscoveryCachedTrait, UseCacheBackendTrait
- class \Drupal\group\Plugin\GroupContentEnablerManager implements \Symfony\Component\DependencyInjection\ContainerAwareInterface, GroupContentEnablerManagerInterface uses \Symfony\Component\DependencyInjection\ContainerAwareTrait
- class \Drupal\Core\Plugin\DefaultPluginManager implements CachedDiscoveryInterface, PluginManagerInterface, CacheableDependencyInterface uses DiscoveryCachedTrait, UseCacheBackendTrait
Expanded class hierarchy of GroupContentEnablerManager
See also
hook_group_content_info_alter()
\Drupal\group\Annotation\GroupContentEnabler
\Drupal\group\Plugin\GroupContentEnablerInterface
\Drupal\group\Plugin\GroupContentEnablerBase
1 file declares its use of GroupContentEnablerManager
- GroupContentEnablerManagerTest.php in tests/
src/ Unit/ GroupContentEnablerManagerTest.php
1 string reference to 'GroupContentEnablerManager'
1 service uses GroupContentEnablerManager
File
- src/
Plugin/ GroupContentEnablerManager.php, line 24
Namespace
Drupal\group\PluginView source
class GroupContentEnablerManager extends DefaultPluginManager implements GroupContentEnablerManagerInterface, ContainerAwareInterface {
use ContainerAwareTrait;
/**
* Contains instantiated handlers keyed by handler type and plugin ID.
*
* @var array
*/
protected $handlers = [];
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The group type storage handler.
*
* @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface
*/
protected $groupTypeStorage;
/**
* A group content type storage handler.
*
* @var \Drupal\group\Entity\Storage\GroupContentTypeStorageInterface
*/
protected $groupContentTypeStorage;
/**
* A collection of vanilla instances of all content enabler plugins.
*
* @var \Drupal\group\Plugin\GroupContentEnablerCollection
*/
protected $allPlugins;
/**
* An list each group type's installed plugins as plugin collections.
*
* @var \Drupal\group\Plugin\GroupContentEnablerCollection[]
*/
protected $groupTypeInstalled = [];
/**
* An static cache of group content type IDs per plugin ID.
*
* @var array[]
*/
protected $pluginGroupContentTypeMap;
/**
* The cache key for the group content type IDs per plugin ID map.
*
* @var string
*/
protected $pluginGroupContentTypeMapCacheKey;
/**
* An static cache of plugin IDs per group type ID.
*
* @var array[]
*/
protected $groupTypePluginMap;
/**
* The cache key for the plugin IDs per group type ID map.
*
* @var string
*/
protected $groupTypePluginMapCacheKey;
/**
* Constructs a GroupContentEnablerManager 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.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct('Plugin/GroupContentEnabler', $namespaces, $module_handler, 'Drupal\\group\\Plugin\\GroupContentEnablerInterface', 'Drupal\\group\\Annotation\\GroupContentEnabler');
$this
->alterInfo('group_content_info');
$this
->setCacheBackend($cache_backend, 'group_content_enablers');
$this->entityTypeManager = $entity_type_manager;
$this->pluginGroupContentTypeMapCacheKey = $this->cacheKey . '_GCT_map';
$this->groupTypePluginMapCacheKey = $this->cacheKey . '_GT_map';
}
/**
* {@inheritdoc}
*/
public function hasHandler($plugin_id, $handler_type) {
if ($definition = $this
->getDefinition($plugin_id, FALSE)) {
if (isset($definition['handlers'][$handler_type])) {
return class_exists($definition['handlers'][$handler_type]);
}
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getHandler($plugin_id, $handler_type) {
if (!isset($this->handlers[$handler_type][$plugin_id])) {
$definition = $this
->getDefinition($plugin_id);
if (!isset($definition['handlers'][$handler_type])) {
throw new InvalidPluginDefinitionException($plugin_id, sprintf('The "%s" plugin did not specify a %s handler.', $plugin_id, $handler_type));
}
$this->handlers[$handler_type][$plugin_id] = $this
->createHandlerInstance($definition['handlers'][$handler_type], $plugin_id, $definition);
}
return $this->handlers[$handler_type][$plugin_id];
}
/**
* {@inheritdoc}
*/
public function createHandlerInstance($class, $plugin_id, array $definition = NULL) {
if (!is_subclass_of($class, 'Drupal\\group\\Plugin\\GroupContentHandlerInterface')) {
throw new InvalidPluginDefinitionException($plugin_id, 'Trying to instantiate a handler that does not implement \\Drupal\\group\\Plugin\\GroupContentHandlerInterface.');
}
$handler = $class::createInstance($this->container, $plugin_id, $definition);
if (method_exists($handler, 'setModuleHandler')) {
$handler
->setModuleHandler($this->moduleHandler);
}
return $handler;
}
/**
* {@inheritdoc}
*/
public function getAccessControlHandler($plugin_id) {
return $this
->getHandler($plugin_id, 'access');
}
/**
* {@inheritdoc}
*/
public function getPermissionProvider($plugin_id) {
return $this
->getHandler($plugin_id, 'permission_provider');
}
/**
* Returns the group type storage handler.
*
* @return \Drupal\Core\Config\Entity\ConfigEntityStorageInterface
* The group type storage handler.
*/
protected function getGroupTypeStorage() {
if (!isset($this->groupTypeStorage)) {
$this->groupTypeStorage = $this->entityTypeManager
->getStorage('group_type');
}
return $this->groupTypeStorage;
}
/**
* Returns the group content type storage handler.
*
* @return \Drupal\group\Entity\Storage\GroupContentTypeStorageInterface
* The group content type storage handler.
*/
protected function getGroupContentTypeStorage() {
if (!isset($this->groupContentTypeStorage)) {
$this->groupContentTypeStorage = $this->entityTypeManager
->getStorage('group_content_type');
}
return $this->groupContentTypeStorage;
}
/**
* {@inheritdoc}
*/
public function getAll() {
if (!isset($this->allPlugins)) {
$collection = new GroupContentEnablerCollection($this, []);
// Add every known plugin to the collection with a vanilla configuration.
foreach ($this
->getDefinitions() as $plugin_id => $plugin_info) {
$collection
->setInstanceConfiguration($plugin_id, [
'id' => $plugin_id,
]);
}
// Sort and set the plugin collection.
$this->allPlugins = $collection
->sort();
}
return $this->allPlugins;
}
/**
* {@inheritdoc}
*/
public function getInstalled(GroupTypeInterface $group_type = NULL) {
return !isset($group_type) ? $this
->getVanillaInstalled() : $this
->getGroupTypeInstalled($group_type);
}
/**
* Retrieves a vanilla instance of every installed plugin.
*
* @return \Drupal\group\Plugin\GroupContentEnablerCollection
* A plugin collection with a vanilla instance of every installed plugin.
*/
protected function getVanillaInstalled() {
// Retrieve a vanilla instance of all known content enabler plugins.
$plugins = clone $this
->getAll();
// Retrieve all installed content enabler plugin IDs.
$installed = $this
->getInstalledIds();
// Remove uninstalled plugins from the collection.
/** @var \Drupal\group\Plugin\GroupContentEnablerCollection $plugins */
foreach ($plugins as $plugin_id => $plugin) {
if (!in_array($plugin_id, $installed)) {
$plugins
->removeInstanceId($plugin_id);
}
}
return $plugins;
}
/**
* Retrieves fully instantiated plugins for a group type.
*
* @param \Drupal\group\Entity\GroupTypeInterface $group_type
* The group type to instantiate the installed plugins for.
*
* @return \Drupal\group\Plugin\GroupContentEnablerCollection
* A plugin collection with fully instantiated plugins for the group type.
*/
protected function getGroupTypeInstalled(GroupTypeInterface $group_type) {
if (!isset($this->groupTypeInstalled[$group_type
->id()])) {
$configurations = [];
$group_content_types = $this
->getGroupContentTypeStorage()
->loadByGroupType($group_type);
// Get the plugin config from every group content type for the group type.
foreach ($group_content_types as $group_content_type) {
$plugin_id = $group_content_type
->getContentPluginId();
// Grab the plugin config from every group content type and amend it
// with the group type ID so the plugin knows what group type to use. We
// also specify the 'id' key because DefaultLazyPluginCollection throws
// an exception if it is not present.
$configuration = $group_content_type
->get('plugin_config');
$configuration['group_type_id'] = $group_type
->id();
$configuration['id'] = $plugin_id;
$configurations[$plugin_id] = $configuration;
}
$plugins = new GroupContentEnablerCollection($this, $configurations);
$plugins
->sort();
$this->groupTypeInstalled[$group_type
->id()] = $plugins;
}
return $this->groupTypeInstalled[$group_type
->id()];
}
/**
* {@inheritdoc}
*/
public function getInstalledIds(GroupTypeInterface $group_type = NULL) {
// If no group type was provided, we can find all installed plugin IDs by
// grabbing the keys from the group content type IDs per plugin ID map.
if (!isset($group_type)) {
return array_keys($this
->getPluginGroupContentTypeMap());
}
// Otherwise, we can find the entry in the plugin IDs per group type ID map.
$map = $this
->getGroupTypePluginMap();
return isset($map[$group_type
->id()]) ? $map[$group_type
->id()] : [];
}
/**
* {@inheritdoc}
*/
public function getPluginIdsByEntityTypeAccess($entity_type_id) {
$plugin_ids = [];
foreach ($this
->getDefinitions() as $plugin_id => $plugin_info) {
if (!empty($plugin_info['entity_access']) && $plugin_info['entity_type_id'] == $entity_type_id) {
$plugin_ids[] = $plugin_id;
}
}
return $plugin_ids;
}
/**
* {@inheritdoc}
*/
public function installEnforced(GroupTypeInterface $group_type = NULL) {
$enforced = [];
// Gather the ID of all plugins that are marked as enforced.
foreach ($this
->getDefinitions() as $plugin_id => $plugin_info) {
if ($plugin_info['enforced']) {
$enforced[] = $plugin_id;
}
}
// If no group type was specified, we check all of them.
/** @var \Drupal\group\Entity\GroupTypeInterface[] $group_types */
$group_types = empty($group_type) ? $this
->getGroupTypeStorage()
->loadMultiple() : [
$group_type,
];
// Search through all of the enforced plugins and install new ones.
foreach ($group_types as $group_type) {
$installed = $this
->getInstalledIds($group_type);
foreach ($enforced as $plugin_id) {
if (!in_array($plugin_id, $installed)) {
$this
->getGroupContentTypeStorage()
->createFromPlugin($group_type, $plugin_id)
->save();
}
}
}
}
/**
* {@inheritdoc}
*/
public function getGroupContentTypeIds($plugin_id) {
$map = $this
->getPluginGroupContentTypeMap();
return isset($map[$plugin_id]) ? $map[$plugin_id] : [];
}
/**
* {@inheritdoc}
*/
public function getPluginGroupContentTypeMap() {
$map = $this
->getCachedPluginGroupContentTypeMap();
if (!isset($map)) {
$map = [];
/** @var \Drupal\group\Entity\GroupContentTypeInterface[] $group_content_types */
$group_content_types = $this
->getGroupContentTypeStorage()
->loadMultiple();
foreach ($group_content_types as $group_content_type) {
$map[$group_content_type
->getContentPluginId()][] = $group_content_type
->id();
}
$this
->setCachedPluginGroupContentTypeMap($map);
}
return $map;
}
/**
* Returns the cached group content type ID map.
*
* @return array|null
* On success this will return the group content ID map (array). On failure
* this should return NULL, indicating to other methods that this has not
* yet been defined. Success with no values should return as an empty array.
*/
protected function getCachedPluginGroupContentTypeMap() {
if (!isset($this->pluginGroupContentTypeMap) && ($cache = $this
->cacheGet($this->pluginGroupContentTypeMapCacheKey))) {
$this->pluginGroupContentTypeMap = $cache->data;
}
return $this->pluginGroupContentTypeMap;
}
/**
* Sets a cache of the group content type ID map.
*
* @param array $map
* The group content type ID map to store in cache.
*/
protected function setCachedPluginGroupContentTypeMap(array $map) {
$this
->cacheSet($this->pluginGroupContentTypeMapCacheKey, $map, Cache::PERMANENT);
$this->pluginGroupContentTypeMap = $map;
}
/**
* {@inheritdoc}
*/
public function getGroupTypePluginMap() {
$map = $this
->getCachedGroupTypePluginMap();
if (!isset($map)) {
$map = [];
/** @var \Drupal\group\Entity\GroupContentTypeInterface[] $group_content_types */
$group_content_types = $this
->getGroupContentTypeStorage()
->loadMultiple();
foreach ($group_content_types as $group_content_type) {
$map[$group_content_type
->getGroupTypeId()][] = $group_content_type
->getContentPluginId();
}
$this
->setCachedGroupTypePluginMap($map);
}
return $map;
}
/**
* Returns the cached group type plugin map.
*
* @return array|null
* On success this will return the group type plugin map (array). On failure
* this should return NULL, indicating to other methods that this has not
* yet been defined. Success with no values should return as an empty array.
*/
protected function getCachedGroupTypePluginMap() {
if (!isset($this->groupTypePluginMap) && ($cache = $this
->cacheGet($this->groupTypePluginMapCacheKey))) {
$this->groupTypePluginMap = $cache->data;
}
return $this->groupTypePluginMap;
}
/**
* Sets a cache of the group type plugin map.
*
* @param array $map
* The group type plugin map to store in cache.
*/
protected function setCachedGroupTypePluginMap(array $map) {
$this
->cacheSet($this->groupTypePluginMapCacheKey, $map, Cache::PERMANENT);
$this->groupTypePluginMap = $map;
}
/**
* {@inheritdoc}
*/
public function clearCachedGroupTypeCollections(GroupTypeInterface $group_type = NULL) {
if (!isset($group_type)) {
$this->groupTypeInstalled = [];
}
else {
$this->groupTypeInstalled[$group_type
->id()] = NULL;
}
}
/**
* {@inheritdoc}
*/
public function clearCachedPluginMaps() {
if ($this->cacheBackend) {
$this->cacheBackend
->delete($this->pluginGroupContentTypeMapCacheKey);
$this->cacheBackend
->delete($this->groupTypePluginMapCacheKey);
}
$this->pluginGroupContentTypeMap = NULL;
$this->groupTypePluginMap = NULL;
// Also clear the array of per group type plugin collections as it shares
// its cache clearing requirements with the group type plugin map.
$this->groupTypeInstalled = [];
}
/**
* {@inheritdoc}
*/
public function clearCachedDefinitions() {
parent::clearCachedDefinitions();
// The collection of all plugins should only change if the plugin
// definitions change, so we can safely reset that here.
$this->allPlugins = NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DefaultPluginManager:: |
protected | property | Additional namespaces the annotation discovery mechanism should scan for annotation definitions. | |
DefaultPluginManager:: |
protected | property | Name of the alter hook if one should be invoked. | |
DefaultPluginManager:: |
protected | property | The cache key. | |
DefaultPluginManager:: |
protected | property | An array of cache tags to use for the cached definitions. | |
DefaultPluginManager:: |
protected | property | A set of defaults to be referenced by $this->processDefinition() if additional processing of plugins is necessary or helpful for development purposes. | 9 |
DefaultPluginManager:: |
protected | property | The module handler to invoke the alter hook. | 1 |
DefaultPluginManager:: |
protected | property | An object that implements \Traversable which contains the root paths keyed by the corresponding namespace to look for plugin implementations. | |
DefaultPluginManager:: |
protected | property | The name of the annotation that contains the plugin definition. | |
DefaultPluginManager:: |
protected | property | The interface each plugin should implement. | 1 |
DefaultPluginManager:: |
protected | property | The subdirectory within a namespace to look for plugins, or FALSE if the plugins are in the top level of the namespace. | |
DefaultPluginManager:: |
protected | function | Invokes the hook to alter the definitions if the alter hook is set. | 1 |
DefaultPluginManager:: |
protected | function | Sets the alter hook name. | |
DefaultPluginManager:: |
protected | function | Extracts the provider from a plugin definition. | |
DefaultPluginManager:: |
protected | function | Finds plugin definitions. | 7 |
DefaultPluginManager:: |
private | function | Fix the definitions of context-aware plugins. | |
DefaultPluginManager:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyInterface:: |
|
DefaultPluginManager:: |
protected | function | Returns the cached plugin definitions of the decorated discovery class. | |
DefaultPluginManager:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyInterface:: |
|
DefaultPluginManager:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyInterface:: |
|
DefaultPluginManager:: |
public | function |
Gets the definition of all plugins for this type. Overrides DiscoveryTrait:: |
2 |
DefaultPluginManager:: |
protected | function |
Gets the plugin discovery. Overrides PluginManagerBase:: |
12 |
DefaultPluginManager:: |
protected | function |
Gets the plugin factory. Overrides PluginManagerBase:: |
|
DefaultPluginManager:: |
public | function | Performs extra processing on plugin definitions. | 13 |
DefaultPluginManager:: |
protected | function | Determines if the provider of a definition exists. | 3 |
DefaultPluginManager:: |
public | function | Initialize the cache backend. | |
DefaultPluginManager:: |
protected | function | Sets a cache of plugin definitions for the decorated discovery class. | |
DefaultPluginManager:: |
public | function |
Disable the use of caches. Overrides CachedDiscoveryInterface:: |
1 |
DiscoveryCachedTrait:: |
protected | property | Cached definitions array. | 1 |
DiscoveryCachedTrait:: |
public | function |
Overrides DiscoveryTrait:: |
3 |
DiscoveryTrait:: |
protected | function | Gets a specific plugin definition. | |
DiscoveryTrait:: |
public | function | ||
GroupContentEnablerManager:: |
protected | property | A collection of vanilla instances of all content enabler plugins. | |
GroupContentEnablerManager:: |
protected | property | The entity type manager. | |
GroupContentEnablerManager:: |
protected | property | A group content type storage handler. | |
GroupContentEnablerManager:: |
protected | property | An list each group type's installed plugins as plugin collections. | |
GroupContentEnablerManager:: |
protected | property | An static cache of plugin IDs per group type ID. | |
GroupContentEnablerManager:: |
protected | property | The cache key for the plugin IDs per group type ID map. | |
GroupContentEnablerManager:: |
protected | property | The group type storage handler. | |
GroupContentEnablerManager:: |
protected | property | Contains instantiated handlers keyed by handler type and plugin ID. | |
GroupContentEnablerManager:: |
protected | property | An static cache of group content type IDs per plugin ID. | |
GroupContentEnablerManager:: |
protected | property | The cache key for the group content type IDs per plugin ID map. | |
GroupContentEnablerManager:: |
public | function |
Clears static and persistent plugin definition caches. Overrides DefaultPluginManager:: |
|
GroupContentEnablerManager:: |
public | function |
Clears the static per group type plugin collection cache. Overrides GroupContentEnablerManagerInterface:: |
|
GroupContentEnablerManager:: |
public | function |
Clears static and persistent plugin ID map caches. Overrides GroupContentEnablerManagerInterface:: |
|
GroupContentEnablerManager:: |
public | function |
Creates new handler instance. Overrides GroupContentEnablerManagerInterface:: |
|
GroupContentEnablerManager:: |
public | function |
Creates a new access control handler instance. Overrides GroupContentEnablerManagerInterface:: |
|
GroupContentEnablerManager:: |
public | function |
Returns a plugin collection of all available content enablers. Overrides GroupContentEnablerManagerInterface:: |
|
GroupContentEnablerManager:: |
protected | function | Returns the cached group type plugin map. | |
GroupContentEnablerManager:: |
protected | function | Returns the cached group content type ID map. | |
GroupContentEnablerManager:: |
public | function |
Retrieves all of the group content type IDs for a content plugin. Overrides GroupContentEnablerManagerInterface:: |
|
GroupContentEnablerManager:: |
protected | function | Returns the group content type storage handler. | |
GroupContentEnablerManager:: |
protected | function | Retrieves fully instantiated plugins for a group type. | |
GroupContentEnablerManager:: |
public | function |
Retrieves a list of plugin IDs per group type ID. Overrides GroupContentEnablerManagerInterface:: |
|
GroupContentEnablerManager:: |
protected | function | Returns the group type storage handler. | |
GroupContentEnablerManager:: |
public | function |
Returns a handler instance for the given plugin and handler. Overrides GroupContentEnablerManagerInterface:: |
|
GroupContentEnablerManager:: |
public | function |
Returns a plugin collection of all installed content enablers. Overrides GroupContentEnablerManagerInterface:: |
|
GroupContentEnablerManager:: |
public | function |
Returns the plugin ID of all content enablers in use. Overrides GroupContentEnablerManagerInterface:: |
|
GroupContentEnablerManager:: |
public | function |
Creates a new permission provider instance. Overrides GroupContentEnablerManagerInterface:: |
|
GroupContentEnablerManager:: |
public | function |
Retrieves a list of group content type IDs per plugin ID. Overrides GroupContentEnablerManagerInterface:: |
|
GroupContentEnablerManager:: |
public | function |
Returns the ID of all plugins that define access for a given entity type. Overrides GroupContentEnablerManagerInterface:: |
|
GroupContentEnablerManager:: |
protected | function | Retrieves a vanilla instance of every installed plugin. | |
GroupContentEnablerManager:: |
public | function |
Checks whether a certain plugin has a certain handler. Overrides GroupContentEnablerManagerInterface:: |
|
GroupContentEnablerManager:: |
public | function |
Installs all plugins which are marked as enforced. Overrides GroupContentEnablerManagerInterface:: |
|
GroupContentEnablerManager:: |
protected | function | Sets a cache of the group type plugin map. | |
GroupContentEnablerManager:: |
protected | function | Sets a cache of the group content type ID map. | |
GroupContentEnablerManager:: |
public | function |
Constructs a GroupContentEnablerManager object. Overrides DefaultPluginManager:: |
|
PluginManagerBase:: |
protected | property | The object that discovers plugins managed by this manager. | |
PluginManagerBase:: |
protected | property | The object that instantiates plugins managed by this manager. | |
PluginManagerBase:: |
protected | property | The object that returns the preconfigured plugin instance appropriate for a particular runtime condition. | |
PluginManagerBase:: |
public | function |
Creates a pre-configured instance of a plugin. Overrides FactoryInterface:: |
12 |
PluginManagerBase:: |
public | function |
Gets a preconfigured instance of a plugin. Overrides MapperInterface:: |
7 |
PluginManagerBase:: |
protected | function | Allows plugin managers to specify custom behavior if a plugin is not found. | 1 |
UseCacheBackendTrait:: |
protected | property | Cache backend instance. | |
UseCacheBackendTrait:: |
protected | property | Flag whether caches should be used or skipped. | |
UseCacheBackendTrait:: |
protected | function | Fetches from the cache backend, respecting the use caches flag. | 1 |
UseCacheBackendTrait:: |
protected | function | Stores data in the persistent cache, respecting the use caches flag. |