Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $condition_id = $form_state->get('condition_id');
     $configuration = $this->conditionExpression->getConfiguration();
     if (empty($condition_id) && !empty($configuration['condition_id'])) {
         $condition_id = $configuration['condition_id'];
         $form_state->set('condition_id', $condition_id);
     }
     // Step 1 of the multistep form.
     if (!$condition_id) {
         $condition_definitions = $this->conditionManager->getGroupedDefinitions();
         $options = [];
         foreach ($condition_definitions as $group => $definitions) {
             foreach ($definitions as $id => $definition) {
                 $options[$group][$id] = $definition['label'];
             }
         }
         $form['condition_id'] = ['#type' => 'select', '#title' => $this->t('Condition'), '#options' => $options, '#required' => TRUE];
         $form['continue'] = ['#type' => 'submit', '#value' => $this->t('Continue'), '#name' => 'continue', '#limit_validation_errors' => [['condition_id']], '#submit' => [static::class . '::submitFirstStep']];
         return $form;
     }
     // Step 2 of the form.
     /** @var \Drupal\rules\Core\RulesConditionInterface $condition */
     $condition = $this->conditionManager->createInstance($condition_id);
     $form['summary'] = ['#markup' => $condition->summary()];
     $context_definitions = $condition->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;
 }
 /**
  * Tests that negating a condition works.
  */
 public function testNegation()
 {
     $this->trueCondition->getContextDefinitions()->willReturn([]);
     $this->trueCondition->refineContextDefinitions([])->shouldBeCalledTimes(1);
     $this->trueCondition->getProvidedContextDefinitions()->willReturn([])->shouldBeCalledTimes(1);
     $this->conditionManager->createInstance('test_condition', ['negate' => TRUE])->willReturn($this->trueCondition->reveal())->shouldBeCalledTimes(1);
     // Create a condition which is negated.
     $condition_expression = new RulesCondition(['condition_id' => 'test_condition', 'negate' => TRUE], '', [], $this->conditionManager->reveal(), $this->processorManager->reveal());
     $this->assertFalse($condition_expression->execute());
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function prepareExecutionMetadataState(ExecutionMetadataStateInterface $metadata_state, ExpressionInterface $until = NULL, $apply_assertions = TRUE)
 {
     if ($until && $this->getUuid() === $until->getUuid()) {
         return TRUE;
     }
     $condition = $this->conditionManager->createInstance($this->configuration['condition_id'], ['negate' => $this->configuration['negate']]);
     // Make sure to refine context first, such that possibly refined definitions
     // of provided context are respected.
     $this->prepareContextWithMetadata($condition, $metadata_state);
     $this->addProvidedContextDefinitions($condition, $metadata_state);
     if ($apply_assertions && !$this->isNegated()) {
         $this->assertMetadata($condition, $metadata_state);
     }
 }