You are here

public static function ContextDefinition::createFromArray in Rules 8.3

Creates a definition object from an exported array of values.

Parameters

array $values: The array of values, as returned by toArray().

Return value

static The created definition.

Throws

\Drupal\Component\Plugin\Exception\ContextException If the required classes are not implemented.

5 calls to ContextDefinition::createFromArray()
ContextDefinition::__construct in src/Context/Annotation/ContextDefinition.php
Constructs a new context definition object.
RulesComponent::createFromConfiguration in src/Engine/RulesComponent.php
Creates a component based on the given configuration array.
RulesComponentConfig::getContextDefinitions in src/Entity/RulesComponentConfig.php
Gets the definitions of the used context.
RulesComponentConfig::getProvidedContextDefinitions in src/Entity/RulesComponentConfig.php
Gets the definitions of the provided context.
RulesEventManager::processDefinition in src/Core/RulesEventManager.php
Performs extra processing on plugin definitions.

File

src/Context/ContextDefinition.php, line 138

Class

ContextDefinition
Extends the core context definition class with useful methods.

Namespace

Drupal\rules\Context

Code

public static function createFromArray(array $values) {
  if (isset($values['class']) && !in_array(ContextDefinitionInterface::class, class_implements($values['class']))) {
    throw new ContextException('ContextDefinition class must implement ' . ContextDefinitionInterface::class . '.');
  }

  // Default to Rules context definition class.
  $values['class'] = isset($values['class']) ? $values['class'] : ContextDefinition::class;
  if (!isset($values['value'])) {
    $values['value'] = 'any';
  }
  $definition = $values['class']::create($values['value']);
  foreach (array_intersect_key(static::$nameMap, $values) as $key => $name) {
    $definition->{$name} = $values[$key];
  }
  return $definition;
}