Commit 1c9e1401 authored by alexpott's avatar alexpott

Issue #2406439 by dawehner: Cleanup EntityDerivative and RouteBuilderInterface

parent a6c29cb6
......@@ -203,13 +203,6 @@ public function rebuild() {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getCollectionDuringRebuild() {
return $this->routeCollection ?: FALSE;
}
/**
* {@inheritdoc}
*/
......
......@@ -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.
*
......
......@@ -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 @@
*
* @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 @@ public function __construct(EntityManagerInterface $entity_manager, RouteProvide
*/
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 @@ public function getDerivativeDefinitions($base_plugin_definition) {
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;
}
......
......@@ -23,7 +23,7 @@
* 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}"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment