Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
31
core/lib/Drupal/Core/Action/ActionBase.php
Normal file
31
core/lib/Drupal/Core/Action/ActionBase.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Action\ActionBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Action;
|
||||
|
||||
use Drupal\Core\Plugin\PluginBase;
|
||||
|
||||
/**
|
||||
* Provides a base implementation for an Action plugin.
|
||||
*
|
||||
* @see \Drupal\Core\Annotation\Action
|
||||
* @see \Drupal\Core\Action\ActionManager
|
||||
* @see \Drupal\Core\Action\ActionInterface
|
||||
* @see plugin_api
|
||||
*/
|
||||
abstract class ActionBase extends PluginBase implements ActionInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function executeMultiple(array $entities) {
|
||||
foreach ($entities as $entity) {
|
||||
$this->execute($entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
66
core/lib/Drupal/Core/Action/ActionInterface.php
Normal file
66
core/lib/Drupal/Core/Action/ActionInterface.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Action\ActionInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Action;
|
||||
|
||||
use Drupal\Component\Plugin\PluginInspectionInterface;
|
||||
use Drupal\Core\Executable\ExecutableInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for an Action plugin.
|
||||
*
|
||||
* @todo WARNING: The action API is going to receive some additions before
|
||||
* release. The following additions are likely to happen:
|
||||
* - The way configuration is handled and configuration forms are built is
|
||||
* likely to change in order for the plugin to be of use for Rules.
|
||||
* - Actions are going to become context-aware in
|
||||
* https://www.drupal.org/node/2011038, what will deprecated the 'type'
|
||||
* annotation.
|
||||
* - Instead of action implementations saving entities, support for marking
|
||||
* required context as to be saved by the execution manager will be added as
|
||||
* part of https://www.drupal.org/node/2347017.
|
||||
* - Actions will receive a data processing API that allows for token
|
||||
* replacements to happen outside of the action plugin implementations,
|
||||
* see https://www.drupal.org/node/2347023.
|
||||
*
|
||||
* @see \Drupal\Core\Annotation\Action
|
||||
* @see \Drupal\Core\Action\ActionManager
|
||||
* @see \Drupal\Core\Action\ActionBase
|
||||
* @see plugin_api
|
||||
*/
|
||||
interface ActionInterface extends ExecutableInterface, PluginInspectionInterface {
|
||||
|
||||
/**
|
||||
* Executes the plugin for an array of objects.
|
||||
*
|
||||
* @param array $objects
|
||||
* An array of entities.
|
||||
*/
|
||||
public function executeMultiple(array $objects);
|
||||
|
||||
/**
|
||||
* Checks object access.
|
||||
*
|
||||
* @param mixed $object
|
||||
* The object to execute the action on.
|
||||
* @param \Drupal\Core\Session\AccountInterface $account
|
||||
* (optional) The user for which to check access, or NULL to check access
|
||||
* for the current user. Defaults to NULL.
|
||||
* @param bool $return_as_object
|
||||
* (optional) Defaults to FALSE.
|
||||
*
|
||||
* @return bool|\Drupal\Core\Access\AccessResultInterface
|
||||
* The access result. Returns a boolean if $return_as_object is FALSE (this
|
||||
* is the default) and otherwise an AccessResultInterface object.
|
||||
* When a boolean is returned, the result of AccessInterface::isAllowed() is
|
||||
* returned, i.e. TRUE means access is explicitly allowed, FALSE means
|
||||
* access is either explicitly forbidden or "no opinion".
|
||||
*/
|
||||
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE);
|
||||
|
||||
}
|
60
core/lib/Drupal/Core/Action/ActionManager.php
Normal file
60
core/lib/Drupal/Core/Action/ActionManager.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Action\ActionManager.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Action;
|
||||
|
||||
use Drupal\Component\Plugin\CategorizingPluginManagerInterface;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Plugin\CategorizingPluginManagerTrait;
|
||||
use Drupal\Core\Plugin\DefaultPluginManager;
|
||||
|
||||
/**
|
||||
* Provides an Action plugin manager.
|
||||
*
|
||||
* @see \Drupal\Core\Annotation\Action
|
||||
* @see \Drupal\Core\Action\ActionInterface
|
||||
* @see \Drupal\Core\Action\ActionBase
|
||||
* @see plugin_api
|
||||
*/
|
||||
class ActionManager extends DefaultPluginManager implements CategorizingPluginManagerInterface {
|
||||
|
||||
use CategorizingPluginManagerTrait;
|
||||
|
||||
/**
|
||||
* Constructs a new class 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/Action', $namespaces, $module_handler, 'Drupal\Core\Action\ActionInterface', 'Drupal\Core\Annotation\Action');
|
||||
$this->alterInfo('action_info');
|
||||
$this->setCacheBackend($cache_backend, 'action_info');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin definitions for this entity type.
|
||||
*
|
||||
* @param string $type
|
||||
* The entity type name.
|
||||
*
|
||||
* @return array
|
||||
* An array of plugin definitions for this entity type.
|
||||
*/
|
||||
public function getDefinitionsByType($type) {
|
||||
return array_filter($this->getDefinitions(), function ($definition) use ($type) {
|
||||
return $definition['type'] === $type;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
26
core/lib/Drupal/Core/Action/ActionPluginCollection.php
Normal file
26
core/lib/Drupal/Core/Action/ActionPluginCollection.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Action\ActionPluginCollection.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Action;
|
||||
|
||||
use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection;
|
||||
|
||||
/**
|
||||
* Provides a container for lazily loading Action plugins.
|
||||
*/
|
||||
class ActionPluginCollection extends DefaultSingleLazyPluginCollection {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return \Drupal\Core\Action\ActionInterface
|
||||
*/
|
||||
public function &get($instance_id) {
|
||||
return parent::get($instance_id);
|
||||
}
|
||||
|
||||
}
|
63
core/lib/Drupal/Core/Action/ConfigurableActionBase.php
Normal file
63
core/lib/Drupal/Core/Action/ConfigurableActionBase.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Action\ConfigurableActionBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Action;
|
||||
|
||||
use Drupal\Component\Plugin\ConfigurablePluginInterface;
|
||||
use Drupal\Core\Action\ActionBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\PluginFormInterface;
|
||||
|
||||
/**
|
||||
* Provides a base implementation for a configurable Action plugin.
|
||||
*/
|
||||
abstract class ConfigurableActionBase extends ActionBase implements ConfigurablePluginInterface, PluginFormInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
|
||||
$this->configuration += $this->defaultConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfiguration() {
|
||||
return $this->configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setConfiguration(array $configuration) {
|
||||
$this->configuration = $configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function calculateDependencies() {
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue