You are here

FormatConverter.php in Bibliography & Citation 8

Same filename and directory in other branches
  1. 2.0.x src/Routing/FormatConverter.php

File

src/Routing/FormatConverter.php
View source
<?php

namespace Drupal\bibcite\Routing;

use Drupal\bibcite\Plugin\BibciteFormatManagerInterface;
use Drupal\Core\ParamConverter\ParamConverterInterface;
use Symfony\Component\Routing\Route;

/**
 * Converts export plugin id to definition array.
 */
class FormatConverter implements ParamConverterInterface {

  /**
   * Format plugins manager service.
   *
   * @var \Drupal\bibcite\Plugin\BibciteFormatManagerInterface
   */
  protected $formatManager;

  /**
   * Format converter constructor.
   *
   * @param \Drupal\bibcite\Plugin\BibciteFormatManagerInterface $format_manager
   *   Format plugins manager service.
   */
  public function __construct(BibciteFormatManagerInterface $format_manager) {
    $this->formatManager = $format_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function convert($value, $definition, $name, array $defaults) {
    if (!empty($value) && $this->formatManager
      ->hasDefinition($value)) {
      return $this->formatManager
        ->createInstance($value);
    }
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function applies($definition, $name, Route $route) {
    return !empty($definition['type']) && $definition['type'] == 'bibcite_format';
  }

}

Classes

Namesort descending Description
FormatConverter Converts export plugin id to definition array.