You are here

EntityTypeParamConverter.php in Synonyms 8

Same filename and directory in other branches
  1. 2.0.x src/ParamConverter/EntityTypeParamConverter.php

File

src/ParamConverter/EntityTypeParamConverter.php
View source
<?php

namespace Drupal\synonyms\ParamConverter;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\ParamConverter\ParamConverterInterface;
use Symfony\Component\Routing\Route;

/**
 * Param converter service for entity types.
 */
class EntityTypeParamConverter implements ParamConverterInterface {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * EntityTypeParamConverter constructor.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function convert($value, $definition, $name, array $defaults) {
    return $this->entityTypeManager
      ->getDefinition($value);
  }

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

}

Classes

Namesort descending Description
EntityTypeParamConverter Param converter service for entity types.