You are here

public function PluginDefinitionConverter::doConvert in Plugin 8.2

Converts path variables to their corresponding objects.

Parameters

mixed $value: The raw value.

mixed[] $converter_definition: The converter definition provided in the route options.

Return value

mixed|null The converted parameter value.

Throws

\Exception

Overrides PluginTypeBasedConverterTrait::doConvert

File

src/ParamConverter/PluginDefinitionConverter.php, line 48

Class

PluginDefinitionConverter
Converts plugin IDs in route parameters to plugin definitions.

Namespace

Drupal\plugin\ParamConverter

Code

public function doConvert($plugin_id, array $converter_definition) {
  $plugin_type = $this->pluginTypeManager
    ->getPluginType($converter_definition['plugin_type_id']);
  if ($plugin_type
    ->getPluginManager()
    ->hasDefinition($plugin_id)) {
    try {
      return $plugin_type
        ->ensureTypedPluginDefinition($plugin_type
        ->getPluginManager()
        ->getDefinition($plugin_id));
    } catch (\InvalidArgumentException $e) {

      // The only way to see if a typed definition can be ensured is by trying
      // to ensure it. An exception is therefore expected and should not
      // bubble up.
      return NULL;
    }
  }
  return NULL;
}