You are here

public function MarkdownParamConverter::convert in Markdown 8.2

Converts path variables to their corresponding objects.

Parameters

mixed $value: The raw value.

mixed $definition: The parameter definition provided in the route options.

string $name: The name of the parameter.

array $defaults: The route defaults array.

Return value

mixed|null The converted parameter value.

Overrides ParamConverterInterface::convert

File

src/ParamConverter/MarkdownParamConverter.php, line 70

Class

MarkdownParamConverter
Parameter convertor for Markdown plugins.

Namespace

Drupal\markdown\ParamConverter

Code

public function convert($value, $definition, $name, array $defaults) {
  $type = substr($definition['type'], 9);
  $configuration = $this->configFactory
    ->get("markdown.{$type}.{$value}")
    ->get();
  switch ($type) {
    case 'parser':
      return $value instanceof ParserInterface ? $value : $this->parserManager
        ->createInstance((string) $value, $configuration);
    case 'extension':
      return $value instanceof ExtensionInterface ? $value : $this->extensionManager
        ->createInstance((string) $value, $configuration);
    case 'allowed_html':
      return $value instanceof AllowedHtmlInterface ? $value : $this->allowedHtmlManager
        ->createInstance((string) $value, $configuration);
  }
}