Issue #2406439 by dawehner: Cleanup EntityDerivative and RouteBuilderInterface

8.0.x
Alex Pott 2015-01-14 08:11:18 +00:00
parent a6c29cb646
commit 1c9e140120
4 changed files with 7 additions and 69 deletions

View File

@ -203,13 +203,6 @@ class RouteBuilder implements RouteBuilderInterface {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getCollectionDuringRebuild() {
return $this->routeCollection ?: FALSE;
}
/**
* {@inheritdoc}
*/

View File

@ -17,18 +17,6 @@ interface RouteBuilderInterface {
*/
public function rebuild();
/**
* Returns the route collection during the rebuild.
*
* Don't use this function unless you really have to! Better pass along the
* collection for yourself during the rebuild.
*
* Every use of this function is a design flaw of your code.
*
* @return \Symfony\Component\Routing\RouteCollection|FALSE
*/
public function getCollectionDuringRebuild();
/**
* Rebuilds the route info and dumps to dumper if necessary.
*

View File

@ -2,10 +2,10 @@
/**
* @file
* Definition of Drupal\rest\Plugin\Derivative\EntityDerivative.
* Definition of Drupal\rest\Plugin\Deriver\EntityDerivative.
*/
namespace Drupal\rest\Plugin\Derivative;
namespace Drupal\rest\Plugin\Deriver;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
@ -19,7 +19,7 @@ use Symfony\Component\Routing\Exception\RouteNotFoundException;
*
* @see \Drupal\rest\Plugin\rest\resource\EntityResource
*/
class EntityDerivative implements ContainerDeriverInterface {
class EntityDeriver implements ContainerDeriverInterface {
/**
* List of derivative definitions.
@ -35,34 +35,14 @@ class EntityDerivative implements ContainerDeriverInterface {
*/
protected $entityManager;
/**
* The route provider.
*
* @var \Drupal\Core\Routing\RouteProviderInterface
*/
protected $routeProvider;
/**
* The route builder.
*
* @var \Drupal\Core\Routing\RouteBuilderInterface
*/
protected $routeBuilder;
/**
* Constructs an EntityDerivative object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
* The route provider.
* @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder
* The route builder.
*/
public function __construct(EntityManagerInterface $entity_manager, RouteProviderInterface $route_provider, RouteBuilderInterface $route_builder) {
public function __construct(EntityManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
$this->routeProvider = $route_provider;
$this->routeBuilder = $route_builder;
}
/**
@ -70,9 +50,7 @@ class EntityDerivative implements ContainerDeriverInterface {
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static(
$container->get('entity.manager'),
$container->get('router.route_provider'),
$container->get('router.builder')
$container->get('entity.manager')
);
}
@ -110,30 +88,9 @@ class EntityDerivative implements ContainerDeriverInterface {
foreach ($default_uris as $link_relation => $default_uri) {
// Check if there are link templates defined for the entity type and
// use the path from the route instead of the default.
$link_template = $entity_type->getLinkTemplate($link_relation);
if (strpos($link_template, '/') !== FALSE) {
if ($link_template = $entity_type->getLinkTemplate($link_relation)) {
$this->derivatives[$entity_type_id]['uri_paths'][$link_relation] = '/' . $link_template;
}
elseif ($route_name = $link_template) {
// @todo remove the try/catch as part of
// http://drupal.org/node/2281645
try {
if (($collection = $this->routeBuilder->getCollectionDuringRebuild()) && $route = $collection->get($route_name)) {
}
else {
$route = $this->routeProvider->getRouteByName($route_name);
}
$this->derivatives[$entity_type_id]['uri_paths'][$link_relation] = $route->getPath();
}
catch (RouteNotFoundException $e) {
// If the route does not exist it means we are in a brittle state
// of module installing/uninstalling, so we simply exclude this
// entity type.
unset($this->derivatives[$entity_type_id]);
// Continue with the next entity type;
continue 2;
}
}
else {
$this->derivatives[$entity_type_id]['uri_paths'][$link_relation] = $default_uri;
}

View File

@ -23,7 +23,7 @@ use Symfony\Component\HttpKernel\Exception\HttpException;
* id = "entity",
* label = @Translation("Entity"),
* serialization_class = "Drupal\Core\Entity\Entity",
* deriver = "Drupal\rest\Plugin\Derivative\EntityDerivative",
* deriver = "Drupal\rest\Plugin\Deriver\EntityDeriver",
* uri_paths = {
* "canonical" = "/entity/{entity_type}/{entity}",
* "http://drupal.org/link-relations/create" = "/entity/{entity_type}"