/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $action_name = $form_state->get('action'); $configuration = $this->actionExpression->getConfiguration(); if (empty($action_name) && !empty($configuration['action_id'])) { $action_name = $configuration['action_id']; } // Step 1 of the multistep form. if (!$action_name) { $action_definitions = $this->actionManager->getGroupedDefinitions(); $options = []; foreach ($action_definitions as $group => $definitions) { foreach ($definitions as $id => $definition) { $options[$group][$id] = $definition['label']; } } $form['action'] = ['#type' => 'select', '#title' => $this->t('Action'), '#options' => $options, '#required' => TRUE]; $form['continue'] = ['#type' => 'submit', '#value' => $this->t('Continue'), '#name' => 'continue', '#limit_validation_errors' => [['action']], '#submit' => [static::class . '::submitFirstStep']]; return $form; } // Step 2 of the form. $action = $this->actionManager->createInstance($action_name); $form['summary'] = ['#markup' => $action->summary()]; $form['action'] = ['#type' => 'value', '#value' => $action_name]; $context_definitions = $action->getContextDefinitions(); $form['context']['#tree'] = TRUE; foreach ($context_definitions as $context_name => $context_definition) { $form = $this->buildContextForm($form, $form_state, $context_name, $context_definition, $configuration); } $form['save'] = ['#type' => 'submit', '#value' => $this->t('Save'), '#name' => 'save']; return $form; }
/** * {@inheritdoc} */ public function executeWithState(RulesStateInterface $state) { $action = $this->actionManager->createInstance($this->configuration['action_id']); // We have to forward the context values from our configuration to the // action plugin. $this->mapContext($action, $state); $action->refineContextdefinitions(); // Send the context value through configured data processor before executing // the action. $this->processData($action, $state); $action->execute(); $auto_saves = $action->autoSaveContext(); foreach ($auto_saves as $context_name) { // Mark parameter contexts for auto saving in the Rules state. $state->saveChangesLater($this->configuration['context_mapping'][$context_name]); } // Now that the action has been executed it can provide additional // context which we will have to pass back in the evaluation state. $this->mapProvidedContext($action, $state); }
/** * {@inheritdoc} */ public function prepareExecutionMetadataState(ExecutionMetadataStateInterface $metadata_state, ExpressionInterface $until = NULL, $apply_assertions = TRUE) { if ($until && $this->getUuid() === $until->getUuid()) { return TRUE; } $action = $this->actionManager->createInstance($this->configuration['action_id']); // Make sure to refine context first, such that possibly refined definitions // of provided context are respected. $this->prepareContextWithMetadata($action, $metadata_state); $this->addProvidedContextDefinitions($action, $metadata_state); if ($apply_assertions) { $this->assertMetadata($action, $metadata_state); } }
/** * {@inheritdoc} */ public function checkIntegrity(ExecutionMetadataStateInterface $metadata_state) { $violation_list = new IntegrityViolationList(); if (empty($this->configuration['action_id'])) { $violation_list->addViolationWithMessage($this->t('Action plugin ID is missing')); return $violation_list; } if (!$this->actionManager->hasDefinition($this->configuration['action_id'])) { $violation_list->addViolationWithMessage($this->t('Action plugin %plugin_id does not exist', ['%plugin_id' => $this->configuration['action_id']])); return $violation_list; } $action = $this->actionManager->createInstance($this->configuration['action_id']); return $this->doCheckIntegrity($action, $metadata_state); }