class ViewsBulkOperationsActionManager in Views Bulk Operations (VBO) 8
Same name and namespace in other branches
- 8.3 src/Service/ViewsBulkOperationsActionManager.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionManager
- 8.2 src/Service/ViewsBulkOperationsActionManager.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionManager
- 4.0.x src/Service/ViewsBulkOperationsActionManager.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionManager
Defines Views Bulk Operations action manager.
Extends the core Action Manager to allow VBO actions define additional configuration.
Hierarchy
- class \Drupal\Component\Plugin\PluginManagerBase implements PluginManagerInterface uses DiscoveryTrait
- class \Drupal\Core\Plugin\DefaultPluginManager implements CachedDiscoveryInterface, PluginManagerInterface, CacheableDependencyInterface uses DiscoveryCachedTrait, UseCacheBackendTrait
- class \Drupal\Core\Action\ActionManager implements CategorizingPluginManagerInterface uses CategorizingPluginManagerTrait
- class \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionManager
- class \Drupal\Core\Action\ActionManager implements CategorizingPluginManagerInterface uses CategorizingPluginManagerTrait
- class \Drupal\Core\Plugin\DefaultPluginManager implements CachedDiscoveryInterface, PluginManagerInterface, CacheableDependencyInterface uses DiscoveryCachedTrait, UseCacheBackendTrait
Expanded class hierarchy of ViewsBulkOperationsActionManager
5 files declare their use of ViewsBulkOperationsActionManager
- ActionsPermissions.php in modules/
actions_permissions/ src/ ActionsPermissions.php - ActionsPermissionsEventSubscriber.php in modules/
actions_permissions/ src/ EventSubscriber/ ActionsPermissionsEventSubscriber.php - ConfigureAction.php in src/
Form/ ConfigureAction.php - ConfirmAction.php in src/
Form/ ConfirmAction.php - ViewsBulkOperationsBulkForm.php in src/
Plugin/ views/ field/ ViewsBulkOperationsBulkForm.php
1 string reference to 'ViewsBulkOperationsActionManager'
1 service uses ViewsBulkOperationsActionManager
File
- src/
Service/ ViewsBulkOperationsActionManager.php, line 18
Namespace
Drupal\views_bulk_operations\ServiceView source
class ViewsBulkOperationsActionManager extends ActionManager {
const ALTER_ACTIONS_EVENT = 'views_bulk_operations.action_definitions';
/**
* Event dispatcher service.
*
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* Additional parameters passed to alter event.
*
* @var array
*/
protected $alterParameters;
/**
* Service constructor.
*
* @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 $cacheBackend
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* The module handler to invoke the alter hook with.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher
* The event dispatcher service.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cacheBackend, ModuleHandlerInterface $moduleHandler, EventDispatcherInterface $eventDispatcher) {
parent::__construct($namespaces, $cacheBackend, $moduleHandler);
$this->eventDispatcher = $eventDispatcher;
$this
->setCacheBackend($cacheBackend, 'views_bulk_operations_action_info');
}
/**
* {@inheritdoc}
*/
protected function findDefinitions() {
$definitions = $this
->getDiscovery()
->getDefinitions();
// Incompatible actions.
$incompatible = [
'node_delete_action',
'user_cancel_user_action',
];
foreach ($definitions as $plugin_id => &$definition) {
$this
->processDefinition($definition, $plugin_id);
if (empty($definition) || in_array($definition['id'], $incompatible)) {
unset($definitions[$plugin_id]);
}
}
$this
->alterDefinitions($definitions);
foreach ($definitions as $plugin_id => $plugin_definition) {
// If the plugin definition is an object, attempt to convert it to an
// array, if that is not possible, skip further processing.
if (is_object($plugin_definition) && !($plugin_definition = (array) $plugin_definition)) {
continue;
}
// If this plugin was provided by a module that does not exist, remove the
// plugin definition.
if (isset($plugin_definition['provider']) && !in_array($plugin_definition['provider'], [
'core',
'component',
]) && !$this
->providerExists($plugin_definition['provider'])) {
unset($definitions[$plugin_id]);
}
}
return $definitions;
}
/**
* {@inheritdoc}
*
* @param array $parameters
* Parameters of the method. Passed to alter event.
*/
public function getDefinitions(array $parameters = []) {
if (empty($parameters['nocache'])) {
$definitions = $this
->getCachedDefinitions();
}
if (!isset($definitions)) {
$this->alterParameters = $parameters;
$definitions = $this
->findDefinitions($parameters);
$this
->setCachedDefinitions($definitions);
}
return $definitions;
}
/**
* Gets a specific plugin definition.
*
* @param string $plugin_id
* A plugin id.
* @param bool $exception_on_invalid
* (optional) If TRUE, an invalid plugin ID will throw an exception.
* @param array $parameters
* Parameters of the method. Passed to alter event.
*
* @return mixed
* A plugin definition, or NULL if the plugin ID is invalid and
* $exception_on_invalid is FALSE.
*
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* Thrown if $plugin_id is invalid and $exception_on_invalid is TRUE.
*/
public function getDefinition($plugin_id, $exception_on_invalid = TRUE, array $parameters = []) {
// Loading all definitions here will not hurt much, as they're cached,
// and we need the option to alter a definition.
$definitions = $this
->getDefinitions($parameters);
if (isset($definitions[$plugin_id])) {
return $definitions[$plugin_id];
}
elseif (!$exception_on_invalid) {
return NULL;
}
throw new PluginNotFoundException($plugin_id, sprintf('The "%s" plugin does not exist.', $plugin_id));
}
/**
* {@inheritdoc}
*/
public function processDefinition(&$definition, $plugin_id) {
// Only arrays can be operated on.
if (!is_array($definition)) {
return;
}
if (!empty($this->defaults) && is_array($this->defaults)) {
$definition = NestedArray::mergeDeep($this->defaults, $definition);
}
// Merge in defaults.
$definition += [
'confirm' => FALSE,
'pass_context' => FALSE,
'pass_view' => FALSE,
];
// Add default confirmation form if confirm set to TRUE
// and not explicitly set.
if ($definition['confirm'] && empty($definition['confirm_form_route_name'])) {
$definition['confirm_form_route_name'] = 'views_bulk_operations.confirm';
}
}
/**
* {@inheritdoc}
*/
protected function alterDefinitions(&$definitions) {
// Let other modules change definitions.
// Main purpose: Action permissions bridge.
$event = new Event();
$event->alterParameters = $this->alterParameters;
$event->definitions =& $definitions;
$this->eventDispatcher
->dispatch(static::ALTER_ACTIONS_EVENT, $event);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ActionManager:: |
public | function | Gets the plugin definitions for this entity type. | |
CategorizingPluginManagerTrait:: |
public | function | ||
CategorizingPluginManagerTrait:: |
public | function | ||
CategorizingPluginManagerTrait:: |
public | function | Returns the module handler used. | |
CategorizingPluginManagerTrait:: |
protected | function | Gets the name of a provider. | |
CategorizingPluginManagerTrait:: |
public | function | ||
CategorizingPluginManagerTrait:: |
protected | function | Processes a plugin definition to ensure there is a category. | |
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 | Sets the alter hook name. | |
DefaultPluginManager:: |
public | function |
Clears static and persistent plugin definition caches. Overrides CachedDiscoveryInterface:: |
5 |
DefaultPluginManager:: |
protected | function | Extracts the provider from a plugin definition. | |
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:: |
protected | function |
Gets the plugin discovery. Overrides PluginManagerBase:: |
12 |
DefaultPluginManager:: |
protected | function |
Gets the plugin factory. Overrides PluginManagerBase:: |
|
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 |
DiscoveryTrait:: |
protected | function | Gets a specific plugin definition. | |
DiscoveryTrait:: |
public | function | ||
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 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
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. | |
ViewsBulkOperationsActionManager:: |
protected | property | Additional parameters passed to alter event. | |
ViewsBulkOperationsActionManager:: |
protected | property | Event dispatcher service. | |
ViewsBulkOperationsActionManager:: |
protected | function |
Invokes the hook to alter the definitions if the alter hook is set. Overrides DefaultPluginManager:: |
|
ViewsBulkOperationsActionManager:: |
constant | |||
ViewsBulkOperationsActionManager:: |
protected | function |
Finds plugin definitions. Overrides DefaultPluginManager:: |
|
ViewsBulkOperationsActionManager:: |
public | function |
Gets a specific plugin definition. Overrides DiscoveryCachedTrait:: |
|
ViewsBulkOperationsActionManager:: |
public | function |
Overrides DefaultPluginManager:: |
|
ViewsBulkOperationsActionManager:: |
public | function |
Performs extra processing on plugin definitions. Overrides DefaultPluginManager:: |
|
ViewsBulkOperationsActionManager:: |
public | function |
Service constructor. Overrides ActionManager:: |