class PluginTypeConverter in Plugin 8.2
Converts plugin type IDs in route parameters to plugin types.
To use it, add a `plugin.plugin_type` key to the route parameter's options. Its value is as follows:
example.route:
path: foo/{bar}
options:
parameters:
bar:
plugin.plugin_type:
# Whether the conversion is enabled. Boolean. Optional. Defaults
# to TRUE.
enabled: TRUE
To use the default behavior, its value is as follows:
example.route:
path: foo/{bar}
options:
parameters:
bar:
plugin.plugin_type: {}
Hierarchy
- class \Drupal\plugin\ParamConverter\PluginTypeConverter implements ParamConverterInterface uses PluginTypeBasedConverterTrait
Expanded class hierarchy of PluginTypeConverter
1 file declares its use of PluginTypeConverter
- PluginTypeConverterTest.php in tests/
src/ Unit/ ParamConverter/ PluginTypeConverterTest.php
1 string reference to 'PluginTypeConverter'
1 service uses PluginTypeConverter
File
- src/
ParamConverter/ PluginTypeConverter.php, line 37
Namespace
Drupal\plugin\ParamConverterView source
class PluginTypeConverter implements ParamConverterInterface {
use PluginTypeBasedConverterTrait;
/**
* {@inheritdoc}
*/
public function doConvert($plugin_type_id, array $converter_definition) {
if ($this->pluginTypeManager
->hasPluginType($plugin_type_id)) {
return $this->pluginTypeManager
->getPluginType($plugin_type_id);
}
return NULL;
}
/**
* {@inheritdoc}
*/
protected function getConverterDefinitionKey() {
return 'plugin.plugin_type';
}
/**
* {@inheritdoc}
*/
protected function getConverterDefinitionConstraint() {
return new Collection([
'enabled' => new Optional(new Type('boolean')),
]);
}
}