Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // plugins: PluginInspectionInterface
- interface ExecutableInterface extends PluginInspectionInterface {
- // Defined by PluginInspectionInterface
- // Possibility to alter parameter definition upon config. -> getDefinition()
- public function getDefinition();
- /**
- * @param array $arguments
- * The arguments using typed data wrappers.
- * @param $state
- *
- * @return array
- * An array of values for the provided variables.
- */
- public function executeByArguments($arguments, $state);
- }
- /**
- * May return variables, save parameters, ..
- */
- interface ActionInterface extends ExecutableInterface {
- }
- // Restriction to return booleans. Fixed definition to provide a boolean.
- // Further restriction: May not change arguments.
- interface ConditionInterface extends ActionInterface {
- }
- /**
- * Handle saving here???
- */
- class ActionExecutionManager {
- public function setExecutionState(ExecutionState $state) {
- $this->state = $state;
- }
- public function execute(ActionInterface $action) {
- // Extract arguments by applying action config.
- $arguments = array('arg1' => $value);
- // Execute and then care about saving.
- $action->executeByArguments($arguments, $this->state);
- $this->state->runPostExecutionTasks();
- }
- }
- // Inject execution manager upon creation.
- // Inject configuration form manager upon creation.
- abstract class ActionBase {
- public function execute() {
- return $this->executionManager->execute($this, func_get_args());
- }
- public function executeByArguments($arguments, ExecutionState $state) {
- // unwrap arguments.
- $this->execute($arg1, $args2, $state);
- }
- public function evaluate($node, $title) {
- $node->title = $title;
- }
- }
- // Move to annotations.
- function hook_action_info() {
- $defintion = array(
- 'label' => t('Update node title'),
- 'parameter' => array(
- 'node' => array(
- 'type' => 'node',
- 'label' => t('Content'),
- 'save' => TRUE,
- ),
- 'text' => array(
- 'type' => 'string',
- 'label' => t('Text'),
- ),
- ),
- 'provides' => array(
- 'new var' => array(
- 'text' => array(
- 'type' => 'string',
- 'label' => 'fooo',
- )
- )
- ),
- );
- }
- function example_usage() {
- $action_manager = new ActionManager();
- $condition_manager = new ConditionManager();
- $action_manager->createInstance('name')
- ->setArgument('node', $node)
- ->setArgument('text', 'new title')
- ->execute();
- $boolean = $condition_manager->createInstance('condition_name')
- ->setArgument('text', 'new title')
- ->execute();
- $action = $action_manager->createInstance('name')
- ->setArgumentBySelector('node', 'user2')
- ->setArgument('text','new title')
- ->execute();
- // Store action configuration.
- $config = $action->getConfiguration();
- // Read/write config to CMI.
- $action_manager->createInstance('name')
- ->applyConfiguration($config)
- ->execute();
- $form = $action_manager->form($action);
- $action_manager->formValidate($action, $form, $form_state);
- $action_manager->formSubmit($action, $form, $form_State);
- list($variable1, $variable2) = $action_manager->createInstance('name')
- ->setArgumentBySelector('node', 'node.referenced_node.entity')
- ->setArgument('text','new title')
- ->addProcessor('text', 'token') // done by the form code?
- ->addProcessor('date', 'offset', '+1 day') // done by the form code?
- ->execute();
- }
- // Rules: RuleElementPlugin -> "condition", "action", "loop", "or", ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement