You are here

public static function RulesComponent::createFromConfiguration in Rules 8.3

Creates a component based on the given configuration array.

Parameters

array $configuration: The component configuration, as returned from ::getConfiguration().

Return value

static

2 calls to RulesComponent::createFromConfiguration()
RulesComponentConfig::getComponent in src/Entity/RulesComponentConfig.php
Gets the Rules component to be edited.
RulesUiConfigHandler::getComponent in src/Ui/RulesUiConfigHandler.php
Gets the currently edited component.

File

src/Engine/RulesComponent.php, line 66

Class

RulesComponent
Handles executable Rules components.

Namespace

Drupal\rules\Engine

Code

public static function createFromConfiguration(array $configuration) {
  $configuration += [
    'context_definitions' => [],
    'provided_context_definitions' => [],
  ];

  // @todo Can we improve this use dependency injection somehow?
  $expression_manager = \Drupal::service('plugin.manager.rules_expression');
  $expression = $expression_manager
    ->createInstance($configuration['expression']['id'], $configuration['expression']);
  $component = static::create($expression);
  foreach ($configuration['context_definitions'] as $name => $definition) {
    $component
      ->addContextDefinition($name, ContextDefinition::createFromArray($definition));
  }
  foreach ($configuration['provided_context_definitions'] as $name => $definition) {
    $component
      ->provideContext($name);
  }
  return $component;
}