You are here

class FormatConverter in Bibliography & Citation 2.0.x

Same name and namespace in other branches
  1. 8 src/Routing/FormatConverter.php \Drupal\bibcite\Routing\FormatConverter

Converts export plugin id to definition array.

Hierarchy

Expanded class hierarchy of FormatConverter

1 string reference to 'FormatConverter'
bibcite.services.yml in ./bibcite.services.yml
bibcite.services.yml
1 service uses FormatConverter
bibcite.format_param_converter in ./bibcite.services.yml
Drupal\bibcite\Routing\FormatConverter

File

src/Routing/FormatConverter.php, line 12

Namespace

Drupal\bibcite\Routing
View source
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';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FormatConverter::$formatManager protected property Format plugins manager service.
FormatConverter::applies public function Determines if the converter applies to a specific route and variable. Overrides ParamConverterInterface::applies
FormatConverter::convert public function Converts path variables to their corresponding objects. Overrides ParamConverterInterface::convert
FormatConverter::__construct public function Format converter constructor.