From 07a709696ee1451251d691cee14afb24e4f2d10a Mon Sep 17 00:00:00 2001 From: Kristiaan Van den Eynde Date: Thu, 21 Jan 2016 12:21:21 +0100 Subject: [PATCH] Issue #2651974 by kristiaanvandeneynde: Entity::urlRouteParameters() should be public (and implemented by field_ui_entity_operation()) --- core/lib/Drupal/Core/Entity/Entity.php | 7 +++++++ core/lib/Drupal/Core/Entity/EntityInterface.php | 14 ++++++++++++++ core/modules/field_ui/field_ui.module | 13 ++++--------- core/modules/views_ui/src/ViewUI.php | 7 +++++++ 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index b49f3d4..8c15bbf 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -321,6 +321,13 @@ protected function urlRouteParameters($rel) { /** * {@inheritdoc} */ + public function getRouteParameters($rel) { + return $this->urlRouteParameters($rel); + } + + /** + * {@inheritdoc} + */ public function uriRelationships() { return array_keys($this->linkTemplates()); } diff --git a/core/lib/Drupal/Core/Entity/EntityInterface.php b/core/lib/Drupal/Core/Entity/EntityInterface.php index 89b99ac..8cd273b 100644 --- a/core/lib/Drupal/Core/Entity/EntityInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityInterface.php @@ -230,6 +230,20 @@ public function toLink($text = NULL, $rel = 'canonical', array $options = []); public function hasLinkTemplate($key); /** + * Gets an array of placeholders for this entity. + * + * This should be called whenever a Url object is constructed for an entity to + * ensure that all the necessary route parameters are being provided. + * + * @param string $rel + * The link relationship type, for example: canonical or edit-form. + * + * @return array + * An array of URI placeholders. + */ + public function getRouteParameters($rel); + + /** * Gets a list of URI relationships supported by this entity. * * @return string[] diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index 597be4f..0d728cf 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -146,31 +146,26 @@ function field_ui_entity_operation(EntityInterface $entity) { // of another and that type has field UI enabled. if (($bundle_of = $info->getBundleOf()) && \Drupal::entityManager()->getDefinition($bundle_of)->get('field_ui_base_route')) { $account = \Drupal::currentUser(); + $route_params = $entity->getRouteParameters('field-ui'); if ($account->hasPermission('administer '. $bundle_of . ' fields')) { $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' => Url::fromRoute("entity.{$bundle_of}.field_ui_fields", $route_params), ); } 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' => Url::fromRoute("entity.entity_form_display.{$bundle_of}.default", $route_params), ); } 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' => Url::fromRoute("entity.entity_view_display.{$bundle_of}.default", $route_params), ); } } diff --git a/core/modules/views_ui/src/ViewUI.php b/core/modules/views_ui/src/ViewUI.php index 33c3284..f569f01 100644 --- a/core/modules/views_ui/src/ViewUI.php +++ b/core/modules/views_ui/src/ViewUI.php @@ -1034,6 +1034,13 @@ public function toLink($text = NULL, $rel = 'edit-form', array $options = []) { /** * {@inheritdoc} */ + public function getRouteParameters($rel) { + return $this->storage->getRouteParameters($rel); + } + + /** + * {@inheritdoc} + */ public function label() { return $this->storage->label(); } -- 2.4.9 (Apple Git-60)