ComponentTypeConverter.php in RNG - Events and Registrations 3.x
File
src/ParamConverter/ComponentTypeConverter.php
View source
<?php
namespace Drupal\rng\ParamConverter;
use Symfony\Component\Routing\Route;
use Drupal\Core\ParamConverter\ParamConverterInterface;
class ComponentTypeConverter implements ParamConverterInterface {
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;
}
}
}
public function applies($definition, $name, Route $route) {
return !empty($definition['type']) && in_array($definition['type'], [
'rng_component_type',
'rng_component_id',
]);
}
}