diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 3d19d73..2f0e03a 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -317,10 +317,11 @@ public function getAdminPath($entity_type, $bundle) { */ public function getAdminRouteInfo($entity_type, $bundle) { $entity_info = $this->getDefinition($entity_type); + $bundle_arg = isset($entity_info['bundle_entity_type']) ? $entity_info['bundle_entity_type'] : 'bundle'; return array( 'route_name' => "field_ui.overview_$entity_type", 'route_parameters' => array( - $entity_info['bundle_entity_type'] => $bundle, + $bundle_arg => $bundle, ) ); } diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index 036eeea..8dc30ba 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -247,12 +247,7 @@ function field_ui_entity_operation_alter(array &$operations, EntityInterface $en */ function field_ui_form_node_type_form_submit($form, &$form_state) { if ($form_state['triggering_element']['#parents'][0] === 'save_continue') { - $form_state['redirect_route'] = array( - 'route_name' => 'field_ui.overview_node', - 'route_parameters' => array( - 'node_type' => $form_state['values']['type'], - ), - ); + $form_state['redirect_route'] = $this->entityManager->getAdminRouteInfo('node', $form_state['values']['type']); } } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php index edb6a7a..f51256b 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php @@ -79,13 +79,7 @@ public function submit(array $form, array &$form_state) { drupal_set_message($this->t('There was a problem removing the %field from the %type content type.', array('%field' => $this->entity->label(), '%type' => $bundle_label)), 'error'); } - $entity_info = $this->entityManager->getDefinition($this->entity->entity_type); - $form_state['redirect_route'] = array( - 'route_name' => 'field_ui.overview_' . $this->entity->entity_type, - 'route_parameters' => array( - $entity_info['bundle_entity_type'] => $this->entity->bundle, - ) - ); + $form_state['redirect_route'] = $this->entityManager->getAdminRouteInfo($this->entity->entity_type, $this->entity->bundle); // Fields are purged on cron. However field module prevents disabling modules // when field types they provided are used in a field until it is fully diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php index 354ff70..8d9ce26 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php @@ -206,13 +206,7 @@ public function submitForm(array &$form, array &$form_state) { $form_state['redirect'] = $next_destination; } else { - $entity_info = $this->entityManager->getDefinition($this->instance->entity_type); - $form_state['redirect_route'] = array( - 'route_name' => 'field_ui.overview_' . $this->instance->entity_type, - 'route_parameters' => array( - $entity_info['bundle_entity_type'] => $this->instance->bundle, - ) - ); + $form_state['redirect_route'] = $this->entityManager->getAdminRouteInfo($this->instance->entity_type, $this->instance->bundle); } } catch (\Exception $e) { diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php index a095d8c..ea00aab 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php @@ -193,13 +193,7 @@ public function submitForm(array &$form, array &$form_state) { $form_state['redirect'] = $next_destination; } else { - $entity_info = $this->entityManager->getDefinition($this->instance->entity_type); - $form_state['redirect_route'] = array( - 'route_name' => 'field_ui.overview_' . $this->instance->entity_type, - 'route_parameters' => array( - $entity_info['bundle_entity_type'] => $this->instance->bundle, - ) - ); + $form_state['redirect_route'] = $this->entityManager->getAdminRouteInfo($this->instance->entity_type, $this->instance->bundle); } } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php b/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php index 1b7d611..048630a 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php @@ -10,6 +10,8 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Routing\RouteProviderInterface; use Drupal\Core\Routing\RouteSubscriberBase; +use Drupal\Core\Routing\RoutingEvents; +use Symfony\Component\Routing\Exception\RouteNotFoundException; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; @@ -52,7 +54,19 @@ protected function routes(RouteCollection $collection) { foreach ($this->manager->getDefinitions() as $entity_type => $entity_info) { $defaults = array(); if ($entity_info['fieldable'] && isset($entity_info['links']['admin-form'])) { - $path = $this->routeProvider->getRouteByName($entity_info['links']['admin-form'])->getPath(); + // First try to get the route from the dynamic_routes collection. + if (!$entity_route = $collection->get($entity_info['links']['admin-form'])) { + // Then try to get the route from the route provider itself, checking + // all previous collections. + try { + $entity_route = $this->routeProvider->getRouteByName($entity_info['links']['admin-form']); + } + // If the route was not found, skip this entity type. + catch (RouteNotFoundException $e) { + continue; + } + } + $path = $entity_route->getPath(); $route = new Route( "$path/fields/{field_instance}", @@ -133,4 +147,13 @@ protected function routes(RouteCollection $collection) { } } + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() { + $events = parent::getSubscribedEvents(); + $events[RoutingEvents::DYNAMIC] = array('onDynamicRoutes', -100); + return $events; + } + } diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Controller/EntityTestController.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Controller/EntityTestController.php index ad22414..a6a42ee 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Controller/EntityTestController.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Controller/EntityTestController.php @@ -30,4 +30,11 @@ public function testEdit(Request $request) { return entity_test_edit($entity); } + /** + * Returns an empty page. + */ + public function testAdmin() { + return ''; + } + } diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php index f1dd221..b4ad49b 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php @@ -39,7 +39,8 @@ * }, * links = { * "canonical" = "entity_test.render", - * "edit-form" = "entity_test.edit_entity_test" + * "edit-form" = "entity_test.edit_entity_test", + * "admin-form" = "entity_test.admin_entity_test" * } * ) */ diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMul.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMul.php index 7580934..e73ff5e 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMul.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTestMul.php @@ -38,7 +38,8 @@ * }, * links = { * "canonical" = "entity_test.edit_entity_test_mul", - * "edit-form" = "entity_test.edit_entity_test_mul" + * "edit-form" = "entity_test.edit_entity_test_mul", + * "admin-form" = "entity_test.admin_entity_test_mul" * } * ) */ diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Routing/RouteSubscriber.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Routing/RouteSubscriber.php index 0379d37..91a43cd 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Routing/RouteSubscriber.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Routing/RouteSubscriber.php @@ -39,6 +39,13 @@ protected function routes(RouteCollection $collection) { )) ); $collection->add("entity_test.edit_$entity_type", $route); + + $route = new Route( + "$entity_type/structure/{bundle}", + array('_content' => '\Drupal\entity_test\Controller\EntityTestController::testAdmin'), + array('_permission' => 'administer entity_test content') + ); + $collection->add("entity_test.admin_$entity_type", $route); } }