Exemple #1
0
 /**
  * {@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 getContextDefinition($name)
 {
     // Pass up the context definitions from the action plugin.
     $definition = $this->actionManager->getDefinition($this->configuration['action_id']);
     if (empty($definition['context'][$name])) {
         throw new ContextException(sprintf("The %s context is not a valid context.", $name));
     }
     return $definition['context'][$name];
 }
 /**
  * {@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);
     }
 }
Exemple #4
0
 /**
  * {@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);
 }