Permalink
Browse files

Separate the actions API from the core actions API.

  • Loading branch information...
fago authored and dasjo committed Jun 7, 2015
1 parent 586f85b commit 55fe6db158d08e2e55e89fc977f3a4e290fe76dc
Showing with 277 additions and 117 deletions.
  1. +3 −0 rules.services.yml
  2. +70 −0 src/Core/Annotation/RulesAction.php
  3. +22 −2 src/Core/RulesActionInterface.php
  4. +46 −0 src/Core/RulesActionManager.php
  5. +22 −0 src/Core/RulesActionManagerInterface.php
  6. +3 −3 src/Plugin/{Action → RulesAction}/BanIP.php
  7. +3 −3 src/Plugin/{Action → RulesAction}/DataCalculateValue.php
  8. +3 −3 src/Plugin/{Action → RulesAction}/DataConvert.php
  9. +3 −3 src/Plugin/{Action → RulesAction}/DataListItemAdd.php
  10. +3 −3 src/Plugin/{Action → RulesAction}/DataListItemRemove.php
  11. +4 −4 src/Plugin/{Action → RulesAction}/EntityCreate.php
  12. +3 −3 src/Plugin/{Action → RulesAction}/EntityCreateDeriver.php
  13. +3 −3 src/Plugin/{Action → RulesAction}/EntityDelete.php
  14. +3 −3 src/Plugin/{Action → RulesAction}/EntityFetchByField.php
  15. +3 −3 src/Plugin/{Action → RulesAction}/EntityFetchById.php
  16. +4 −4 src/Plugin/{Action → RulesAction}/EntityPathAliasCreate.php
  17. +3 −3 src/Plugin/{Action → RulesAction}/EntityPathAliasCreateDeriver.php
  18. +3 −3 src/Plugin/{Action → RulesAction}/EntitySave.php
  19. +3 −3 src/Plugin/{Action → RulesAction}/PathAliasCreate.php
  20. +3 −3 src/Plugin/{Action → RulesAction}/PathAliasDeleteByAlias.php
  21. +3 −3 src/Plugin/{Action → RulesAction}/PathAliasDeleteByPath.php
  22. +3 −3 src/Plugin/{Action → RulesAction}/SendAccountEmail.php
  23. +3 −3 src/Plugin/{Action → RulesAction}/SystemMessage.php
  24. +3 −3 src/Plugin/{Action → RulesAction}/SystemSendEmail.php
  25. +3 −3 src/Plugin/{Action → RulesAction}/UserBlock.php
  26. +3 −3 src/Plugin/{Action → RulesAction}/UserRoleAdd.php
  27. +3 −3 src/Plugin/{Action → RulesAction}/UserUnblock.php
  28. +3 −3 src/Plugin/{Action → RulesAction}/VariableAdd.php
  29. +6 −6 src/Plugin/RulesExpression/RulesAction.php
  30. +1 −1 src/Tests/NodeIntegrationTest.php
  31. +0 −1 src/Tests/RulesDrupalTestBase.php
  32. +3 −3 tests/modules/rules_test/src/Plugin/{Action → RulesAction}/TestLogAction.php
  33. +3 −3 tests/modules/rules_test/src/Plugin/{Action → RulesAction}/TestNodeAction.php
  34. +3 −3 tests/modules/rules_test/src/Plugin/{Action → RulesAction}/TestStringAction.php
  35. +1 −1 tests/src/Integration/Action/BanIPTest.php
  36. +1 −1 tests/src/Integration/Action/DataCalculateValueTest.php
  37. +1 −1 tests/src/Integration/Action/DataConvertTest.php
  38. +1 −1 tests/src/Integration/Action/DataListItemAddTest.php
  39. +1 −1 tests/src/Integration/Action/DataListItemRemoveTest.php
  40. +1 −1 tests/src/Integration/Action/EntityCreateTest.php
  41. +1 −1 tests/src/Integration/Action/EntityDeleteTest.php
  42. +1 −1 tests/src/Integration/Action/EntityFetchByFieldTest.php
  43. +1 −1 tests/src/Integration/Action/EntityFetchByIdTest.php
  44. +1 −1 tests/src/Integration/Action/EntityPathAliasCreateTest.php
  45. +1 −1 tests/src/Integration/Action/EntitySaveTest.php
  46. +1 −1 tests/src/Integration/Action/PathAliasCreateTest.php
  47. +1 −1 tests/src/Integration/Action/PathAliasDeleteByAliasTest.php
  48. +1 −1 tests/src/Integration/Action/PathAliasDeleteByPathTest.php
  49. +1 −1 tests/src/Integration/Action/SendAccountEmailTest.php
  50. +1 −1 tests/src/Integration/Action/SystemMessageTest.php
  51. +2 −2 tests/src/Integration/Action/SystemSendEmailTest.php
  52. +1 −1 tests/src/Integration/Action/UserBlockTest.php
  53. +1 −1 tests/src/Integration/Action/UserRoleAddTest.php
  54. +1 −1 tests/src/Integration/Action/UserUnblockTest.php
  55. +2 −2 tests/src/Integration/Action/VariableAddTest.php
  56. +4 −4 tests/src/Integration/RulesIntegrationTestBase.php
View
@@ -2,6 +2,9 @@ services:
plugin.manager.rules_expression:
class: Drupal\rules\Engine\ExpressionPluginManager
arguments: ['@container.namespaces', '@module_handler']
+ plugin.manager.rules_action:
+ class: Drupal\rules\Core\RulesActionManager
+ parent: default_plugin_manager
plugin.manager.rules_data_processor:
class: Drupal\rules\Context\DataProcessorManager
arguments: ['@container.namespaces', '@module_handler']
@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\rules\Core\Annotation\RulesAction.
+ */
+
+namespace Drupal\rules\Core\Annotation;
+
+use Drupal\Component\Annotation\Plugin;
+
+/**
+ * Defines a Rules Action annotation object.
+ *
+ * Plugin Namespace: Plugin\RulesAction
+ *
+ * For a working example, see \Drupal\rules\Plugin\RulesAction\BanIP
+ *
+ * @see \Drupal\rules\Core\RulesActionInterface
+ * @see \Drupal\rules\Core\RulesActionManagerInterface
+ * @see \Drupal\rules\Core\RulesActionBase
+ * @see plugin_api
+ *
+ * @Annotation
+ */
+class RulesAction extends Plugin {
+
+ /**
+ * The plugin ID.
+ *
+ * @var string
+ */
+ public $id;
+
+ /**
+ * The human-readable name of the action plugin.
+ *
+ * @ingroup plugin_translatable
+ *
+ * @var \Drupal\Core\Annotation\Translation
+ */
+ public $label;
+
+ /**
+ * The category under which the action should be listed in the UI.
+ *
+ * @var \Drupal\Core\Annotation\Translation
+ *
+ * @ingroup plugin_translatable
+ */
+ public $category;
+
+ /**
+ * Defines the used context of the action plugin.
+ *
+ * Array keys are the names of the contexts and values context definitions.
+ *
+ * @var \Drupal\Core\Annotation\ContextDefinition[]
+ */
+ public $context = [];
+
+ /**
+ * Defines the provided context of the action plugin.
+ *
+ * Array keys are the names of the contexts and values context definitions.
+ *
+ * @var \Drupal\Core\Annotation\ContextDefinition[]
+ */
+ public $provides = [];
+}
@@ -7,14 +7,15 @@
namespace Drupal\rules\Core;
+use Drupal\Core\Executable\ExecutableInterface;
+use Drupal\Core\Session\AccountInterface;
use Drupal\rules\Context\ContextAwarePluginInterface;
-use Drupal\Core\Action\ActionInterface;
use Drupal\rules\Context\ContextProviderInterface;
/**
* Extends the core ActionInterface to provide context.
*/
-interface RulesActionInterface extends ActionInterface, ContextAwarePluginInterface, ContextProviderInterface {
+interface RulesActionInterface extends ExecutableInterface, ContextAwarePluginInterface, ContextProviderInterface {
/**
* Returns a list of context names that should be auto-saved after execution.
@@ -25,4 +26,23 @@
*/
public function autoSaveContext();
+ /**
+ * 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);
}
@@ -0,0 +1,46 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\rules\Core\RulesActionManager.
+ */
+
+namespace Drupal\rules\Core;
+
+use Drupal\Core\Cache\CacheBackendInterface;
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\Plugin\CategorizingPluginManagerTrait;
+use Drupal\Core\Plugin\Context\ContextAwarePluginManagerTrait;
+use Drupal\Core\Plugin\DefaultPluginManager;
+
+/**
+ * Provides an Action plugin manager for the Rules actions API.
+ *
+ * @see \Drupal\Core\Annotation\Action
+ * @see \Drupal\Core\Action\ActionInterface
+ * @see \Drupal\Core\Action\ActionBase
+ * @see plugin_api
+ */
+class RulesActionManager extends DefaultPluginManager implements RulesActionManagerInterface {
+
+ use CategorizingPluginManagerTrait;
+ use ContextAwarePluginManagerTrait;
+
+ /**
+ * 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/RulesAction', $namespaces, $module_handler, 'Drupal\rules\Core\RulesActionInterface', 'Drupal\rules\Core\Annotation\RulesAction');
+ $this->alterInfo('rules_action_info');
+ $this->setCacheBackend($cache_backend, 'rules_action_info');
+ }
+
+}
@@ -0,0 +1,22 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\rules\CoreRulesActionManagerInterface.
+ */
+namespace Drupal\rules\Core;
+
+use Drupal\Component\Plugin\CategorizingPluginManagerInterface;
+use Drupal\Core\Plugin\Context\ContextAwarePluginManagerInterface;
+
+/**
+ * Interface the Rules Action plugin manager of the Rules actions API.
+ *
+ * @see \Drupal\Core\Annotation\Action
+ * @see \Drupal\Core\Action\ActionInterface
+ * @see \Drupal\Core\Action\ActionBase
+ * @see plugin_api
+ */
+interface RulesActionManagerInterface extends CategorizingPluginManagerInterface, ContextAwarePluginManagerInterface {
+
+}
@@ -2,10 +2,10 @@
/**
* @file
- * Contains \Drupal\rules\Plugin\Action\BanIP.
+ * Contains \Drupal\rules\Plugin\RulesAction\BanIP.
*/
-namespace Drupal\rules\Plugin\Action;
+namespace Drupal\rules\Plugin\RulesAction;
use Drupal\ban\BanIpManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
@@ -16,7 +16,7 @@
/**
* Provides the 'Ban IP' action.
*
- * @Action(
+ * @RulesAction(
* id = "rules_ban_ip",
* label = @Translation("Ban IP"),
* category = @Translation("Ban"),
@@ -2,17 +2,17 @@
/**
* @file
- * Contains \Drupal\rules\Plugin\Action\DataCalculateValue.
+ * Contains \Drupal\rules\Plugin\RulesAction\DataCalculateValue.
*/
-namespace Drupal\rules\Plugin\Action;
+namespace Drupal\rules\Plugin\RulesAction;
use Drupal\rules\Core\RulesActionBase;
/**
* Provides a 'numeric calculation' action.
*
- * @Action(
+ * @RulesAction(
* id = "rules_data_calculate_value",
* label = @Translation("Calculates a numeric value"),
* category = @Translation("Data"),
@@ -2,16 +2,16 @@
/**
* @file
- * Contains \Drupal\rules\Plugin\Action\DataConvert.
+ * Contains \Drupal\rules\Plugin\RulesAction\DataConvert.
*/
-namespace Drupal\rules\Plugin\Action;
+namespace Drupal\rules\Plugin\RulesAction;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\rules\Core\RulesActionBase;
/**
- * @Action(
+ * @RulesAction(
* id = "rules_data_convert",
* label = @Translation("Convert data"),
* category = @Translation("Data"),
@@ -2,17 +2,17 @@
/**
* @file
- * Contains \Drupal\rules\Plugin\Action\DataListItemAdd.
+ * Contains \Drupal\rules\Plugin\RulesAction\DataListItemAdd.
*/
-namespace Drupal\rules\Plugin\Action;
+namespace Drupal\rules\Plugin\RulesAction;
use Drupal\rules\Core\RulesActionBase;
/**
* Provides an 'Add list item' action.
*
- * @Action(
+ * @RulesAction(
* id = "rules_list_item_add",
* label = @Translation("Add list item"),
* category = @Translation("Data"),
@@ -2,17 +2,17 @@
/**
* @file
- * Contains \Drupal\rules\Plugin\Action\DataListItemRemove.
+ * Contains \Drupal\rules\Plugin\RulesAction\DataListItemRemove.
*/
-namespace Drupal\rules\Plugin\Action;
+namespace Drupal\rules\Plugin\RulesAction;
use Drupal\rules\Core\RulesActionBase;
/**
* Provides a 'Remove item from list' action.
*
- * @Action(
+ * @RulesAction(
* id = "rules_list_item_remove",
* label = @Translation("Remove item from list"),
* category = @Translation("Data"),
@@ -2,10 +2,10 @@
/**
* @file
- * Contains \Drupal\rules\Plugin\Action\EntityCreate.
+ * Contains \Drupal\rules\Plugin\RulesAction\EntityCreate.
*/
-namespace Drupal\rules\Plugin\Action;
+namespace Drupal\rules\Plugin\RulesAction;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\rules\Core\RulesActionBase;
@@ -15,9 +15,9 @@
/**
* Provides a generic 'Create a new entity' action.
*
- * @Action(
+ * @RulesAction(
* id = "rules_entity_create",
- * deriver = "Drupal\rules\Plugin\Action\EntityCreateDeriver",
+ * deriver = "Drupal\rules\Plugin\RulesAction\EntityCreateDeriver",
* )
*
* @todo: Add access callback information from Drupal 7.
@@ -2,10 +2,10 @@
/**
* @file
- * Contains \Drupal\rules\Plugin\Action\EntityCreateDeriver.
+ * Contains \Drupal\rules\Plugin\RulesAction\EntityCreateDeriver.
*/
-namespace Drupal\rules\Plugin\Action;
+namespace Drupal\rules\Plugin\RulesAction;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Entity\ContentEntityTypeInterface;
@@ -19,7 +19,7 @@
/**
* Derives entity create plugin definitions based on content entity types.
*
- * @see \Drupal\rules\Plugin\Action\EntityCreate
+ * @see \Drupal\rules\Plugin\RulesAction\EntityCreate
*/
class EntityCreateDeriver extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
@@ -2,17 +2,17 @@
/**
* @file
- * Contains \Drupal\rules\Plugin\Action\EntityDelete.
+ * Contains \Drupal\rules\Plugin\RulesAction\EntityDelete.
*/
-namespace Drupal\rules\Plugin\Action;
+namespace Drupal\rules\Plugin\RulesAction;
use Drupal\rules\Core\RulesActionBase;
/**
* Provides a 'Delete entity' action.
*
- * @Action(
+ * @RulesAction(
* id = "rules_entity_delete",
* label = @Translation("Delete entity"),
* category = @Translation("Entity"),
@@ -2,10 +2,10 @@
/**
* @file
- * Contains \Drupal\rules\Plugin\Action\EntityFetchByField.
+ * Contains \Drupal\rules\Plugin\RulesAction\EntityFetchByField.
*/
-namespace Drupal\rules\Plugin\Action;
+namespace Drupal\rules\Plugin\RulesAction;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
@@ -15,7 +15,7 @@
/**
* Provides a 'Fetch entities by field' action.
*
- * @Action(
+ * @RulesAction(
* id = "rules_entity_fetch_by_field",
* label = @Translation("Fetch entities by field"),
* category = @Translation("Entity"),
Oops, something went wrong.

0 comments on commit 55fe6db

Please sign in to comment.