/**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     $rules_components = $this->storage->loadMultiple();
     foreach ($rules_components as $rules_component) {
         $component_config = $rules_component->get('component');
         $expression_definition = $this->expressionManager->getDefinition($component_config['expression']['id']);
         $this->derivatives[$rules_component->id()] = ['label' => $this->t('@expression_type: @label', ['@expression_type' => $expression_definition['label'], '@label' => $rules_component->label()]), 'category' => $this->t('Components'), 'component_id' => $rules_component->id(), 'context' => $rules_component->getContextDefinitions(), 'provides' => $rules_component->getProvidedContextDefinitions()] + $base_plugin_definition;
     }
     return $this->derivatives;
 }
示例#2
0
 /**
  * Constructs a new class instance.
  *
  * @param array $configuration
  *   A configuration array containing information about the plugin instance.
  * @param string $plugin_id
  *   The plugin_id for the plugin instance.
  * @param array $plugin_definition
  *   The plugin implementation definition.
  * @param \Drupal\rules\Engine\ExpressionManagerInterface $expression_manager
  *   The rules expression plugin manager.
  */
 public function __construct(array $configuration, $plugin_id, $plugin_definition, ExpressionManagerInterface $expression_manager)
 {
     parent::__construct($configuration, $plugin_id, $plugin_definition);
     $this->expressionManager = $expression_manager;
     $configuration += ['actions' => []];
     foreach ($configuration['actions'] as $action_config) {
         $action = $expression_manager->createInstance($action_config['id'], $action_config);
         $this->addExpressionObject($action);
     }
 }
示例#3
0
 /**
  * Constructs a new class instance.
  *
  * @param array $configuration
  *   A configuration array containing information about the plugin instance.
  * @param string $plugin_id
  *   The plugin_id for the plugin instance.
  * @param array $plugin_definition
  *   The plugin implementation definition.
  * @param \Drupal\rules\Engine\ExpressionManagerInterface $expression_manager
  *   The rules expression plugin manager.
  */
 public function __construct(array $configuration, $plugin_id, $plugin_definition, ExpressionManagerInterface $expression_manager)
 {
     parent::__construct($configuration, $plugin_id, $plugin_definition);
     $configuration += ['conditions' => [], 'actions' => []];
     // Per default the outer condition container of a rule is initialized as
     // conjunction (AND), meaning that all conditions in it must evaluate to
     // TRUE to fire the actions.
     $this->conditions = $expression_manager->createInstance('rules_and', $configuration['conditions']);
     $this->actions = $expression_manager->createInstance('rules_action_set', $configuration['actions']);
 }
 /**
  * Constructor.
  *
  * @param array $configuration
  *   A configuration array containing information about the plugin instance.
  * @param string $plugin_id
  *   The plugin_id for the plugin instance.
  * @param array $plugin_definition
  *   The plugin implementation definition.
  * @param \Drupal\rules\Engine\ExpressionManagerInterface $expression_manager
  *   The rules expression plugin manager.
  * @param \Drupal\Component\Uuid\UuidInterface $uuid_service
  *   The UUID generating service.
  */
 public function __construct(array $configuration, $plugin_id, $plugin_definition, ExpressionManagerInterface $expression_manager, UuidInterface $uuid_service)
 {
     parent::__construct($configuration, $plugin_id, $plugin_definition);
     $this->expressionManager = $expression_manager;
     $this->uuidService = $uuid_service;
     $configuration += ['actions' => []];
     foreach ($configuration['actions'] as $uuid => $action_config) {
         $action = $expression_manager->createInstance($action_config['id'], $action_config);
         $this->actions[$uuid] = $action;
     }
 }
示例#5
0
 /**
  * Tests that nested rules are properly executed.
  *
  * @covers ::execute
  */
 public function testNestedRules()
 {
     $this->testActionExpression->executeWithState(Argument::type(ExecutionStateInterface::class))->shouldBeCalledTimes(1);
     $nested = new Rule([], 'rules_rule', [], $this->expressionManager->reveal());
     // We need to replace the action and conditon container to not have the same
     // instances as in the outer rule.
     $nested->setConditions(new RulesAnd([], 'rules_and', [], $this->expressionManager->reveal()));
     $nested->setActions(new ActionSet([], 'rules_action_set', [], $this->expressionManager->reveal()));
     $nested->addExpressionObject($this->trueConditionExpression->reveal())->addExpressionObject($this->testActionExpression->reveal());
     $this->rule->addExpressionObject($this->trueConditionExpression->reveal())->addExpressionObject($nested)->execute();
 }
示例#6
0
 /**
  * Provides the page title on the form.
  */
 public function getTitle(ReactionRuleConfig $reaction_config, $expression_id)
 {
     $expression = $this->expressionManager->createInstance($expression_id);
     return $this->t('Add @expression', ['@expression' => $expression->getLabel()]);
 }
 /**
  * {@inheritdoc}
  */
 public function addExpression($plugin_id, ContextConfig $config = NULL)
 {
     return $this->addExpressionObject($this->expressionManager->createInstance($plugin_id, $config ? $config->toArray() : []));
 }
示例#8
0
 /**
  * Tests that provided context definitons are created from configuration.
  */
 public function testProvidedDefinitionFromConfig()
 {
     $rule = new Rule(['provided_definitions' => ['node' => ContextDefinition::create('entity:node')->setLabel('node')->toArray()]], 'rules_rule', [], $this->expressionManager->reveal());
     $provided_definition = $rule->getProvidedContextDefinition('node');
     $this->assertSame($provided_definition->getDataType(), 'entity:node');
 }
 /**
  * Provides the page title on the form.
  */
 public function getTitle(RulesUiHandlerInterface $rules_ui_handler, $expression_id)
 {
     $this->expressionId = $expression_id;
     $expression = $this->expressionManager->createInstance($this->expressionId);
     return $this->t('Add @expression', ['@expression' => $expression->getLabel()]);
 }