You are here

class MarkdownParamConverter in Markdown 8.2

Parameter convertor for Markdown plugins.

Hierarchy

Expanded class hierarchy of MarkdownParamConverter

1 string reference to 'MarkdownParamConverter'
markdown.services.yml in ./markdown.services.yml
markdown.services.yml
1 service uses MarkdownParamConverter
paramconverter.markdown in ./markdown.services.yml
Drupal\markdown\ParamConverter\MarkdownParamConverter

File

src/ParamConverter/MarkdownParamConverter.php, line 18

Namespace

Drupal\markdown\ParamConverter
View source
class MarkdownParamConverter implements ParamConverterInterface {

  /**
   * The Config Factory service.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The Markdown Allowed HTML Plugin Manager service.
   *
   * @var \Drupal\markdown\PluginManager\AllowedHtmlManager
   */
  protected $allowedHtmlManager;

  /**
   * The Markdown Extension Plugin Manager service.
   *
   * @var \Drupal\markdown\PluginManager\ExtensionManagerInterface
   */
  protected $extensionManager;

  /**
   * The Markdown Parser Plugin Manager service.
   *
   * @var \Drupal\markdown\PluginManager\ParserManagerInterface
   */
  protected $parserManager;

  /**
   * MarkdownParamConverter constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
   *   The Config Factory service.
   * @param \Drupal\markdown\PluginManager\ParserManagerInterface $parserManager
   *   The Markdown Parser Plugin Manager service.
   * @param \Drupal\markdown\PluginManager\ExtensionManagerInterface $extensionManager
   *   The Markdown Extension Plugin Manager service.
   * @param \Drupal\markdown\PluginManager\AllowedHtmlManager $allowedHtmlManager
   *   The Markdown Allowed HTML Plugin Manager service.
   */
  public function __construct(ConfigFactoryInterface $configFactory, ParserManagerInterface $parserManager, ExtensionManagerInterface $extensionManager, AllowedHtmlManager $allowedHtmlManager) {
    $this->configFactory = $configFactory;
    $this->parserManager = $parserManager;
    $this->extensionManager = $extensionManager;
    $this->allowedHtmlManager = $allowedHtmlManager;
  }

  /**
   * {@inheritdoc}
   */
  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);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function applies($definition, $name, Route $route) {
    return isset($definition['type']) && strpos($definition['type'], 'markdown:') !== FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MarkdownParamConverter::$allowedHtmlManager protected property The Markdown Allowed HTML Plugin Manager service.
MarkdownParamConverter::$configFactory protected property The Config Factory service.
MarkdownParamConverter::$extensionManager protected property The Markdown Extension Plugin Manager service.
MarkdownParamConverter::$parserManager protected property The Markdown Parser Plugin Manager service.
MarkdownParamConverter::applies public function Determines if the converter applies to a specific route and variable. Overrides ParamConverterInterface::applies
MarkdownParamConverter::convert public function Converts path variables to their corresponding objects. Overrides ParamConverterInterface::convert
MarkdownParamConverter::__construct public function MarkdownParamConverter constructor.