From 42b263ea5e83ecf0e5f72058f9873420467302de 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 | 14 ++------------ core/lib/Drupal/Core/Entity/EntityInterface.php | 14 ++++++++++++++ core/modules/field/src/Entity/FieldConfig.php | 2 +- core/modules/field_ui/field_ui.module | 13 ++++--------- core/modules/views_ui/src/ViewUI.php | 7 +++++++ 5 files changed, 28 insertions(+), 22 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/src/Entity/FieldConfig.php b/core/modules/field/src/Entity/FieldConfig.php index 8e0e0b4..398dece 100644 --- a/core/modules/field/src/Entity/FieldConfig.php +++ b/core/modules/field/src/Entity/FieldConfig.php @@ -266,7 +266,7 @@ protected function linkTemplates() { /** * {@inheritdoc} */ - protected function urlRouteParameters($rel) { + public function urlRouteParameters($rel) { $parameters = parent::urlRouteParameters($rel); $entity_type = \Drupal::entityManager()->getDefinition($this->entity_type); $bundle_parameter_key = $entity_type->getBundleEntityType() ?: 'bundle'; 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), ); } } diff --git a/core/modules/views_ui/src/ViewUI.php b/core/modules/views_ui/src/ViewUI.php index 33c3284..2e07a9d 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 urlRouteParameters($rel) { + return $this->storage->urlRouteParameters($rel); + } + + /** + * {@inheritdoc} + */ public function label() { return $this->storage->label(); } -- 2.4.9 (Apple Git-60)