You are here

public function ComponentTypeConverter::convert in RNG - Events and Registrations 3.x

Same name and namespace in other branches
  1. 8.2 src/ParamConverter/ComponentTypeConverter.php \Drupal\rng\ParamConverter\ComponentTypeConverter::convert()
  2. 8 src/ParamConverter/ComponentTypeConverter.php \Drupal\rng\ParamConverter\ComponentTypeConverter::convert()

Converts path variables to their corresponding objects.

Parameters

mixed $value: The raw value.

mixed $definition: The parameter definition provided in the route options.

string $name: The name of the parameter.

array $defaults: The route defaults array.

Return value

mixed|null The converted parameter value.

Overrides ParamConverterInterface::convert

File

src/ParamConverter/ComponentTypeConverter.php, line 16

Class

ComponentTypeConverter
Provides upcasting for RNG event type rules components.

Namespace

Drupal\rng\ParamConverter

Code

public function convert($value, $definition, $name, array $defaults) {
  if ($definition['type'] == 'rng_component_type') {
    return in_array($value, [
      'condition',
      'action',
    ]) ? $value : NULL;
  }
  elseif ($definition['type'] == 'rng_component_id') {
    $event_type_rule = $defaults['rng_event_type_rule'];
    $component_type = $defaults['component_type'];
    $components = [];
    if ($component_type == 'condition') {
      $components = $event_type_rule
        ->getConditions();
    }
    elseif ($component_type == 'action') {
      $components = $event_type_rule
        ->getActions();
    }
    if (in_array($value, array_keys($components))) {
      return $value;
    }
  }
}