You are here

class EntityRevisionParamConverter in Entity API 8.0

Parameter converter for single revisions.

Hierarchy

Expanded class hierarchy of EntityRevisionParamConverter

1 file declares its use of EntityRevisionParamConverter
EntityRevisionParamConverterTest.php in tests/src/Unit/ParamConverter/EntityRevisionParamConverterTest.php
Contains \Drupal\Tests\entity\Unit\ParamConverter\EntityRevisionParamConverterTest.
1 string reference to 'EntityRevisionParamConverter'
entity.services.yml in ./entity.services.yml
entity.services.yml
1 service uses EntityRevisionParamConverter
param_converter.entity_revision in ./entity.services.yml
\Drupal\entity\ParamConverter\EntityRevisionParamConverter

File

src/ParamConverter/EntityRevisionParamConverter.php, line 18
Contains \Drupal\entity\ParamConverter\EntityRevisionParamConverter.

Namespace

Drupal\entity\ParamConverter
View source
class EntityRevisionParamConverter implements ParamConverterInterface {

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

  /**
   * Creates a new EntityRevisionParamConverter instance.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function convert($value, $definition, $name, array $defaults) {
    list(, $entity_type_id) = explode(':', $definition['type']);
    $entity_storage = $this->entityTypeManager
      ->getStorage($entity_type_id);
    return $entity_storage
      ->loadRevision($value);
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
EntityRevisionParamConverter::$entityTypeManager protected property The entity type manager.
EntityRevisionParamConverter::applies public function Determines if the converter applies to a specific route and variable. Overrides ParamConverterInterface::applies
EntityRevisionParamConverter::convert public function Converts path variables to their corresponding objects. Overrides ParamConverterInterface::convert
EntityRevisionParamConverter::__construct public function Creates a new EntityRevisionParamConverter instance.