You are here

class ComponentTypeConverter in RNG - Events and Registrations 8

Same name and namespace in other branches
  1. 8.2 src/ParamConverter/ComponentTypeConverter.php \Drupal\rng\ParamConverter\ComponentTypeConverter
  2. 3.x src/ParamConverter/ComponentTypeConverter.php \Drupal\rng\ParamConverter\ComponentTypeConverter

Provides upcasting for RNG event type rules components.

Hierarchy

Expanded class hierarchy of ComponentTypeConverter

1 string reference to 'ComponentTypeConverter'
rng.services.yml in ./rng.services.yml
rng.services.yml
1 service uses ComponentTypeConverter
rng.paramconverter.entity_type_rule_component in ./rng.services.yml
Drupal\rng\ParamConverter\ComponentTypeConverter

File

src/ParamConverter/ComponentTypeConverter.php, line 11

Namespace

Drupal\rng\ParamConverter
View source
class ComponentTypeConverter implements ParamConverterInterface {

  /**
   * {@inheritdoc}
   */
  public function convert($value, $definition, $name, array $defaults) {
    if ($definition['type'] == 'rng_component_type') {
      return in_array($value, [
        'condition',
        'action',
      ]) ? $value : NULL;
    }
    else {
      if ($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();
        }
        else {
          if ($component_type == 'action') {
            $components = $event_type_rule
              ->getActions();
          }
        }
        if (in_array($value, array_keys($components))) {
          return $value;
        }
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function applies($definition, $name, Route $route) {
    return !empty($definition['type']) && in_array($definition['type'], [
      'rng_component_type',
      'rng_component_id',
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ComponentTypeConverter::applies public function Determines if the converter applies to a specific route and variable. Overrides ParamConverterInterface::applies
ComponentTypeConverter::convert public function Converts path variables to their corresponding objects. Overrides ParamConverterInterface::convert