You are here

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

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'
plugin.services.yml in ./plugin.services.yml
plugin.services.yml
1 service uses PluginTypeConverter
plugin.paramconverter.plugin_type in ./plugin.services.yml
Drupal\plugin\ParamConverter\PluginTypeConverter

File

src/ParamConverter/PluginTypeConverter.php, line 37

Namespace

Drupal\plugin\ParamConverter
View 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')),
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginTypeBasedConverterTrait::$pluginTypeManager protected property The plugin type manager.
PluginTypeBasedConverterTrait::applies public function Implements \Drupal\Core\ParamConverter\ParamConverterInterface::applies().
PluginTypeBasedConverterTrait::convert public function Implements \Drupal\Core\ParamConverter\ParamConverterInterface::convert().
PluginTypeBasedConverterTrait::getConverterDefinition protected function Gets the converter-specific parameter definition.
PluginTypeBasedConverterTrait::validateParameterDefinition protected function Validates a route parameter's definition.
PluginTypeBasedConverterTrait::__construct public function Constructs a new instance.
PluginTypeConverter::doConvert public function Converts path variables to their corresponding objects. Overrides PluginTypeBasedConverterTrait::doConvert
PluginTypeConverter::getConverterDefinitionConstraint protected function Gets the parameter's converter definition validation constraint. Overrides PluginTypeBasedConverterTrait::getConverterDefinitionConstraint
PluginTypeConverter::getConverterDefinitionKey protected function Gets the top-level route parameter definition key for this converter. Overrides PluginTypeBasedConverterTrait::getConverterDefinitionKey