Commit 3a0d2303 authored by Klaus Purer's avatar Klaus Purer
Browse files

Issue #2664700: Expose Rules components as action plugin

parent 691dbebf
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
# Per default the schema of arbitrary context values of an action cannot be
# typed. Actions that need translatability or other features of the config
# system must specify their context value schema explicitly, see examples below.
rules.action.context_values.*:
  type: ignore
  label: Context values

rules.action.context_values.rules_system_message:
  type: mapping
  label: Message action context values
+3 −3
Original line number Diff line number Diff line
@@ -7,11 +7,11 @@ rules_component:
      label: 'Context definitions'
      sequence:
        - type: rules.context.definition
    provided_context:
    provided_context_definitions:
      type: sequence
      label: 'Names of provided context'
      label: 'Provided context definitions'
      sequence:
        - type: string
        - type: rules.context.definition
    expression:
      type: rules_expression.[id]
      label: 'Expression configuration'
+11 −8
Original line number Diff line number Diff line
@@ -178,6 +178,13 @@ class ExecutionState implements ExecutionStateInterface {
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getAutoSaveSelectors() {
    return array_keys($this->saveLater);
  }

  /**
   * {@inheritdoc}
   */
@@ -185,15 +192,11 @@ class ExecutionState implements ExecutionStateInterface {
    // Make changes permanent.
    foreach ($this->saveLater as $selector => $flag) {
      $typed_data = $this->fetchDataByPropertyPath($selector);
      // The returned data can be NULL, only save it if we actually have
      // something here.
      if ($typed_data) {
      // Things that can be saved must have a save() method, right?
      // Saving is always done at the root of the typed data tree, for example
      // on the entity level.
      $typed_data->getRoot()->getValue()->save();
    }
    }
    return $this;
  }

+9 −0
Original line number Diff line number Diff line
@@ -121,6 +121,15 @@ interface ExecutionStateInterface {
   */
  public function saveChangesLater($selector);

  /**
   * Returns the list of variables that should be auto-saved after execution.
   *
   * @return string[]
   *   The list of data selectors that specify the target object to be saved.
   *   Example: node.uid.entity.
   */
  public function getAutoSaveSelectors();

  /**
   * Saves all variables that have been marked for auto saving.
   *
+3 −3
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ class RulesComponent {
  public static function createFromConfiguration(array $configuration) {
    $configuration += [
      'context_definitions' => [],
      'provided_context' => [],
      'provided_context_definitions' => [],
    ];
    // @todo: Can we improve this use dependency injection somehow?
    $expression_manager = \Drupal::service('plugin.manager.rules_expression');
@@ -78,7 +78,7 @@ class RulesComponent {
    foreach ($configuration['context_definitions'] as $name => $definition) {
      $component->addContextDefinition($name, ContextDefinition::createFromArray($definition));
    }
    foreach ($configuration['provided_context'] as $name) {
    foreach ($configuration['provided_context_definitions'] as $name => $definition) {
      $component->provideContext($name);
    }
    return $component;
@@ -122,7 +122,7 @@ class RulesComponent {
      'context_definitions' => array_map(function (ContextDefinitionInterface $definition) {
        return $definition->toArray();
      }, $this->contextDefinitions),
      'provided_context' => $this->providedContext,
      'provided_context_definitions' => $this->providedContext,
    ];
  }

Loading