EntityRevisionParamConverter.php in Entity API 8.0
Namespace
Drupal\entity\ParamConverterFile
src/ParamConverter/EntityRevisionParamConverter.phpView source
<?php
/**
* @file
* Contains \Drupal\entity\ParamConverter\EntityRevisionParamConverter.
*/
namespace Drupal\entity\ParamConverter;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\ParamConverter\ParamConverterInterface;
use Symfony\Component\Routing\Route;
/**
* Parameter converter for single revisions.
*/
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;
}
}
Classes
Name | Description |
---|---|
EntityRevisionParamConverter | Parameter converter for single revisions. |