From 3f1800448a8b2e55f67668c610f78c0209d971d3 Mon Sep 17 00:00:00 2001 From: Kristiaan Van den Eynde Date: Mon, 18 Jan 2016 11:28:48 +0100 Subject: [PATCH] Issue #2651974: Entity::urlRouteParameters() should be public (and implemented by field_ui_entity_operation()) --- core/lib/Drupal/Core/Entity/Entity.php | 14 ++------------ core/lib/Drupal/Core/Entity/EntityInterface.php | 14 ++++++++++++++ core/modules/field_ui/field_ui.module | 13 ++++--------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index b49f3d4..b724d74 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -292,19 +292,9 @@ public function url($rel = 'canonical', $options = array()) { } /** - * Gets an array of placeholders for this entity. - * - * Individual entity classes may override this method to add additional - * placeholders if desired. If so, they should be sure to replicate the - * property caching logic. - * - * @param string $rel - * The link relationship type, for example: canonical or edit-form. - * - * @return array - * An array of URI placeholders. + * {@inheritdoc} */ - protected function urlRouteParameters($rel) { + public function urlRouteParameters($rel) { $uri_route_parameters = []; if ($rel != 'collection') { diff --git a/core/lib/Drupal/Core/Entity/EntityInterface.php b/core/lib/Drupal/Core/Entity/EntityInterface.php index 89b99ac..7688dee 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 urlRouteParameters($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..5eda7aa 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->urlRouteParameters('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), ); } } -- 2.4.9 (Apple Git-60)