From 14ae81d488acbbbc87d6a9cef20fca2d2aefb830 Mon Sep 17 00:00:00 2001 From: Kristiaan Van den Eynde Date: Mon, 29 Aug 2016 14:58:37 +0200 Subject: [PATCH] Issue #2651974 by kristiaanvandeneynde: Expose Entity::urlRouteParameters() and implement it in field_ui_entity_operation() --- core/modules/field_ui/field_ui.module | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index 5134cad..4b80331 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -106,6 +106,26 @@ function field_ui_entity_type_build(array &$entity_types) { } /** + * Implements hook_entity_type_alter(). + */ +function field_ui_entity_type_alter(array &$entity_types) { + /** @var \Drupal\Core\Routing\RouteProvider $route_provider */ + $route_provider = \Drupal::service('router.route_provider'); + + /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ + foreach ($entity_types as $entity_type) { + // Add manage fields and display link relations and templates if this entity + // type is the bundle of another and that type has field UI enabled. + if (($bundle_of = $entity_type->getBundleOf()) && ($base_route = $entity_types[$bundle_of]->get('field_ui_base_route'))) { + $field_ui_path = $route_provider->getRouteByName($base_route)->getPath() . '/fields'; + $entity_type->setLinkTemplate('drupal:field-ui-fields', $field_ui_path); + $entity_type->setLinkTemplate('drupal:field-ui-form-display', $field_ui_path . '/form-display'); + $entity_type->setLinkTemplate('drupal:field-ui-display', $field_ui_path . '/display'); + } + } +} + +/** * Implements hook_entity_bundle_create(). */ function field_ui_entity_bundle_create($entity_type, $bundle) { @@ -148,27 +168,21 @@ function field_ui_entity_operation(EntityInterface $entity) { $operations['manage-fields'] = array( 'title' => t('Manage fields'), 'weight' => 15, - 'url' => Url::fromRoute("entity.{$bundle_of}.field_ui_fields", array( - $entity->getEntityTypeId() => $entity->id(), - )), + 'url' => $entity->toUrl('drupal:field-ui-fields'), ); } if ($account->hasPermission('administer ' . $bundle_of . ' form display')) { $operations['manage-form-display'] = array( 'title' => t('Manage form display'), 'weight' => 20, - 'url' => Url::fromRoute("entity.entity_form_display.{$bundle_of}.default", array( - $entity->getEntityTypeId() => $entity->id(), - )), + 'url' => $entity->toUrl('drupal:field-ui-form-display'), ); } if ($account->hasPermission('administer ' . $bundle_of . ' display')) { $operations['manage-display'] = array( 'title' => t('Manage display'), 'weight' => 25, - 'url' => Url::fromRoute("entity.entity_view_display.{$bundle_of}.default", array( - $entity->getEntityTypeId() => $entity->id(), - )), + 'url' => $entity->toUrl('drupal:field-ui-display'), ); } } -- 2.4.9 (Apple Git-60)