diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index a988135..5166d32 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -207,8 +207,8 @@ public function preSave(EntityStorageControllerInterface $storage_controller) { /** * {@inheritdoc} */ - public function uri() { - return parent::uri('edit-form'); + public function uri($rel = 'edit-form') { + return parent::uri($rel); } } diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php index 979dddd..5e8b380 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php @@ -32,31 +32,19 @@ public function load() { */ public function getOperations(EntityInterface $entity) { $operations = parent::getOperations($entity); - $uri = $entity->uri(); - - // Ensure the edit operation exists since it is access controlled. - if (isset($operations['edit'])) { - // For configuration entities edit path is the MENU_DEFAULT_LOCAL_TASK and - // therefore should be accessed by the short route. - $operations['edit']['href'] = $uri['path']; - } if ($this->entityInfo->hasKey('status')) { - if (!$entity->status()) { + if (!$entity->status() && $this->entityInfo->hasLinkTemplate('enable')) { $operations['enable'] = array( 'title' => t('Enable'), - 'href' => $uri['path'] . '/enable', - 'options' => $uri['options'], 'weight' => -10, - ); + ) + $entity->uri('enable'); } - else { + elseif ($this->entityInfo->hasLinkTemplate('disable')) { $operations['disable'] = array( 'title' => t('Disable'), - 'href' => $uri['path'] . '/disable', - 'options' => $uri['options'], 'weight' => 40, - ); + ) + $entity->uri('disable'); } } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 9d502d2..0bcd35f 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -73,13 +73,6 @@ protected $fieldDefinitions; /** - * Local cache for URI placeholder substitution values. - * - * @var array - */ - protected $uriPlaceholderReplacements; - - /** * Local cache for the available language objects. * * @var array diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 2e4a7ea..ea0673b 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -38,13 +38,21 @@ protected $enforceIsNew; /** - * The route provider service. + * Local cache for URI route placeholders. * - * @var \Drupal\Core\Routing\RouteProviderInterface + * @var array */ - protected $routeProvider; + protected $uriRouteParameters; /** + * The URL generator. + * + * @var \Drupal\Core\Routing\UrlGeneratorInterface + */ + protected $urlGenerator; + + /** + * * Constructs an Entity object. * * @param array $values @@ -153,24 +161,10 @@ public function uri($rel = 'canonical') { // The links array might contain URI templates set in annotations. $link_templates = $entity_info->getLinkTemplates(); - $template = NULL; if (isset($link_templates[$rel])) { - try { - $template = $this->routeProvider()->getRouteByName($link_templates[$rel])->getPath(); - } - catch (RouteNotFoundException $e) { - // Fall back to a non-template-based URI. - } - } - if ($template) { - // If there is a template for the given relationship type, do the - // placeholder replacement and use that as the path. - $replacements = $this->uriPlaceholderReplacements(); - $uri['path'] = str_replace(array_keys($replacements), array_values($replacements), $template); - - // @todo Remove this once http://drupal.org/node/1888424 is in and we can - // move the BC handling of / vs. no-/ to the generator. - $uri['path'] = trim($uri['path'], '/'); + // If there is a template for the given relationship type, generate the path. + $uri['route_name'] = $link_templates[$rel]; + $uri['route_parameters'] = $this->uriRouteParameters(); // Pass the entity data to url() so that alter functions do not need to // look up this entity again. @@ -214,6 +208,15 @@ public function uri($rel = 'canonical') { } /** + * {@inheritdoc} + */ + public function url($rel = 'canonical', $options = array()) { + $uri = $this->uri($rel); + $options += $uri['options']; + return $this->urlGenerator()->generateFromRoute($uri['route_name'], $uri['route_parameters'], $options); + } + + /** * Returns an array of placeholders for this entity. * * Individual entity classes may override this method to add additional @@ -223,17 +226,14 @@ public function uri($rel = 'canonical') { * @return array * An array of URI placeholders. */ - protected function uriPlaceholderReplacements() { - if (empty($this->uriPlaceholderReplacements)) { - $this->uriPlaceholderReplacements = array( - '{entityType}' => $this->entityType(), - '{bundle}' => $this->bundle(), - '{id}' => $this->id(), - '{uuid}' => $this->uuid(), - '{' . $this->entityType() . '}' => $this->id(), - ); + protected function uriRouteParameters() { + if (empty($this->uriRouteParameters)) { + $this->uriRouteParameters[$this->entityType()] = $this->id(); + if ($this->entityType() != $this->bundle()) { + $this->uriRouteParameters[$this->entityInfo()->getBundleEntityType()] = $this->bundle(); + } } - return $this->uriPlaceholderReplacements; + return $this->uriRouteParameters; } /** @@ -387,16 +387,16 @@ public function changed() { } /** - * Wraps the route provider service. + * Wraps the URL generator. * - * @return \Drupal\Core\Routing\RouteProviderInterface - * The route provider. + * @return \Drupal\Core\Routing\UrlGeneratorInterface + * The URL generator. */ - protected function routeProvider() { - if (!$this->routeProvider) { - $this->routeProvider = \Drupal::service('router.route_provider'); + protected function urlGenerator() { + if (!$this->urlGenerator) { + $this->urlGenerator = \Drupal::urlGenerator(); } - return $this->routeProvider; + return $this->urlGenerator; } } diff --git a/core/lib/Drupal/Core/Entity/EntityInterface.php b/core/lib/Drupal/Core/Entity/EntityInterface.php index b9f1d5e..5fa4125 100644 --- a/core/lib/Drupal/Core/Entity/EntityInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityInterface.php @@ -101,7 +101,7 @@ public function label(); * An array containing the 'path' and 'options' keys used to build the URI * of the entity, and matching the signature of url(). */ - public function uri(); + public function uri($rel = 'canonical'); /** * Returns a list of URI relationships supported by this entity. @@ -240,4 +240,14 @@ public function referencedEntities(); */ public function changed(); + /** + * @todo. + * + * @param string $rel + * @param array $options + * + * @return string + */ + public function url($rel = 'canonical', $options = array()); + } diff --git a/core/lib/Drupal/Core/Entity/EntityListController.php b/core/lib/Drupal/Core/Entity/EntityListController.php index fdbc6a9..386d087 100644 --- a/core/lib/Drupal/Core/Entity/EntityListController.php +++ b/core/lib/Drupal/Core/Entity/EntityListController.php @@ -112,24 +112,18 @@ protected function getLabel(EntityInterface $entity) { * {@inheritdoc} */ public function getOperations(EntityInterface $entity) { - $uri = $entity->uri(); - $operations = array(); - if ($entity->access('update')) { + if ($entity->access('update') && $this->entityInfo->hasLinkTemplate('edit-form')) { $operations['edit'] = array( 'title' => $this->t('Edit'), - 'href' => $uri['path'] . '/edit', - 'options' => $uri['options'], 'weight' => 10, - ); + ) + $entity->uri('edit-form'); } - if ($entity->access('delete')) { + if ($entity->access('delete') && $this->entityInfo->hasLinkTemplate('delete-form')) { $operations['delete'] = array( 'title' => $this->t('Delete'), - 'href' => $uri['path'] . '/delete', - 'options' => $uri['options'], 'weight' => 100, - ); + ) + $entity->uri('delete-form'); } return $operations; diff --git a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php index 4cb05aa..5771821 100644 --- a/core/lib/Drupal/Core/Entity/EntityTypeInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityTypeInterface.php @@ -315,17 +315,14 @@ public function isFieldable(); * HTML page must also define an "edit-form" relationship. * * By default, the following placeholders are supported: - * - entityType: The machine name of the entity type. - * - bundle: The bundle machine name of the entity. - * - id: The unique ID of the entity. - * - uuid: The UUID of the entity. * - [entityType]: The entity type itself will also be a valid token for the * ID of the entity. For instance, a placeholder of {node} used on the Node - * class would have the same value as {id}. This is generally preferred - * over "id" for better self-documentation. + * class. + * - [bundleEntityType]: The bundle machine name itself. For instance, a + * placeholder of {node_type} used on the Node class. * * Specific entity types may also expand upon this list by overriding the - * Entity::uriPlaceholderReplacements() method. + * Entity::uriRouteParameters() method. * * @link http://www.iana.org/assignments/link-relations/link-relations.xml @endlink * @link http://tools.ietf.org/html/rfc6570 @endlink diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockListController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockListController.php index efa31b3..1f49a87 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockListController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockListController.php @@ -36,10 +36,7 @@ public function buildRow(EntityInterface $entity) { */ public function getOperations(EntityInterface $entity) { $operations = parent::getOperations($entity); - // The custom block edit path does not contain '/edit'. if (isset($operations['edit'])) { - $uri = $entity->uri(); - $operations['edit']['href'] = $uri['path']; $operations['edit']['query']['destination'] = 'admin/structure/block/custom-blocks'; } return $operations; diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php index 070171d..9ee9a1a 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php @@ -42,7 +42,7 @@ public function buildHeader() { */ public function buildRow(EntityInterface $entity) { $uri = $entity->uri(); - $row['type'] = l($entity->label(), $uri['path'], $uri['options']); + $row['type'] = \Drupal::l($entity->label(), $uri['route_name'], $uri['route_parameters'], $uri['options']); $row['description'] = filter_xss_admin($entity->description); return $row + parent::buildRow($entity); } diff --git a/core/modules/comment/lib/Drupal/comment/Form/DeleteForm.php b/core/modules/comment/lib/Drupal/comment/Form/DeleteForm.php index 60b2036..f226305 100644 --- a/core/modules/comment/lib/Drupal/comment/Form/DeleteForm.php +++ b/core/modules/comment/lib/Drupal/comment/Form/DeleteForm.php @@ -63,7 +63,8 @@ protected function actions(array $form, array &$form_state) { // @todo Convert to getCancelRoute() after http://drupal.org/node/1987778. $uri = $this->commentManager->getParentEntityUri($this->entity); - $actions['cancel']['#href'] = $uri['path']; + $actions['cancel']['#route_name'] = $uri['route_name']; + $actions['cancel']['#route_parameters'] = $uri['route_parameters']; return $actions; } @@ -99,8 +100,7 @@ public function submit(array $form, array &$form_state) { // Clear the cache so an anonymous user sees that his comment was deleted. Cache::invalidateTags(array('content' => TRUE)); - $uri = $this->commentManager->getParentEntityUri($this->entity); - $form_state['redirect'] = $uri['path']; + $form_state['redirect_route'] = $this->commentManager->getParentEntityUri($this->entity); } } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityStatusUITest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityStatusUITest.php index da36cab..332f65f 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityStatusUITest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityStatusUITest.php @@ -41,17 +41,17 @@ function testCRUD() { ); $this->drupalPostForm('admin/structure/config_test/add', $edit, 'Save'); - $uri = entity_load('config_test', $id)->uri(); + $entity = entity_load('config_test', $id); // Disable an entity. - $disable_path = "{$uri['path']}/disable"; + $disable_path = $entity->url('disable'); $this->assertLinkByHref($disable_path); $this->drupalGet($disable_path); $this->assertResponse(200); $this->assertNoLinkByHref($disable_path); // Enable an entity. - $enable_path = "{$uri['path']}/enable"; + $enable_path = $entity->url('enable'); $this->assertLinkByHref($enable_path); $this->drupalGet($enable_path); $this->assertResponse(200); diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigTest.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigTest.php index 34217a9..fe35a84 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigTest.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/Entity/ConfigTest.php @@ -33,7 +33,11 @@ * "status" = "status" * }, * links = { - * "edit-form" = "config_test.entity" + * "add-form" = "config_test.entity_add", + * "edit-form" = "config_test.entity", + * "delete-form" = "config_test.entity_delete", + * "enable" = "config_test.entity_enable", + * "disable" = "config_test.entity_disable" * } * ) */ diff --git a/core/modules/contact/lib/Drupal/contact/MessageFormController.php b/core/modules/contact/lib/Drupal/contact/MessageFormController.php index ca4a607..50c10a7 100644 --- a/core/modules/contact/lib/Drupal/contact/MessageFormController.php +++ b/core/modules/contact/lib/Drupal/contact/MessageFormController.php @@ -208,8 +208,7 @@ public function save(array $form, array &$form_state) { // To avoid false error messages caused by flood control, redirect away from // the contact form; either to the contacted user account or the front page. if ($message->isPersonal() && user_access('access user profiles')) { - $uri = $message->getPersonalRecipient()->uri(); - $form_state['redirect'] = array($uri['path'], $uri['options']); + $form_state['redirect_route'] = $message->getPersonalRecipient()->uri(); } else { $form_state['redirect_route']['route_name'] = ''; diff --git a/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php b/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php index e99c9b0..491d712 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php @@ -461,6 +461,7 @@ function entityFormDeleteTranslation($form, &$form_state) { $entity = $form_controller->getEntity(); $uri = $entity->uri('drupal:content-translation-overview'); $form_langcode = $form_controller->getFormLangcode($form_state); + // @todo. $form_state['redirect'] = $uri['path'] . '/delete/' . $form_langcode; } diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php b/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php index 7c2e381..9e98de5 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php @@ -511,7 +511,7 @@ public function isTranslatable() { /** * {@inheritdoc} */ - public function uri() { + public function uri($rel = 'edit-form') { $path = \Drupal::entityManager()->getAdminPath($this->entity_type, $this->bundle); // Use parent URI as fallback, if path is empty. diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index cdcc9be..47b7c61 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -121,6 +121,15 @@ function field_ui_entity_info(&$entity_info) { /** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */ $entity_info['field_instance']->setForm('delete', 'Drupal\field_ui\Form\FieldDeleteForm'); $entity_info['field_entity']->setList('Drupal\field_ui\FieldListController'); + + foreach ($entity_info as $info) { + if ($bundle = $info->getBundleOf()) { + $info + ->setLinkTemplate('field_ui-fields', "field_ui.overview_$bundle") + ->setLinkTemplate('field_ui-form-display', "field_ui.form_display_overview_$bundle") + ->setLinkTemplate('field_ui-display', "field_ui.display_overview_$bundle"); + } + } } /** @@ -169,30 +178,23 @@ function field_ui_entity_operation_alter(array &$operations, EntityInterface $en // Add manage fields and display links if this entity type is the bundle // of another. if ($bundle_of = $info->getBundleOf()) { - $uri = $entity->uri(); if (user_access('administer '. $bundle_of . ' fields')) { $operations['manage-fields'] = array( 'title' => t('Manage fields'), - 'href' => $uri['path'] . '/fields', - 'options' => $uri['options'], 'weight' => 15, - ); + ) + $entity->uri('field_ui-fields'); } if (user_access('administer '. $bundle_of . ' form display')) { $operations['manage-form-display'] = array( 'title' => t('Manage form display'), - 'href' => $uri['path'] . '/form-display', - 'options' => $uri['options'], 'weight' => 20, - ); + ) + $entity->uri('field_ui-form-display'); } if (user_access('administer '. $bundle_of . ' display')) { $operations['manage-display'] = array( 'title' => t('Manage display'), - 'href' => $uri['path'] . '/display', - 'options' => $uri['options'], 'weight' => 25, - ); + ) + $entity->uri('field_ui-display'); } } } diff --git a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php index aee3ffc..5d69e36 100644 --- a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php +++ b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php @@ -40,6 +40,7 @@ * "uuid" = "uuid" * }, * links = { + * "flush-form" = "image.style_flush", * "edit-form" = "image.style_edit" * } * ) diff --git a/core/modules/image/lib/Drupal/image/ImageStyleListController.php b/core/modules/image/lib/Drupal/image/ImageStyleListController.php index bf5618b..d0c2754 100644 --- a/core/modules/image/lib/Drupal/image/ImageStyleListController.php +++ b/core/modules/image/lib/Drupal/image/ImageStyleListController.php @@ -79,13 +79,10 @@ public function buildRow(EntityInterface $entity) { * {@inheritdoc} */ public function getOperations(EntityInterface $entity) { - $uri = $entity->uri('edit-form'); $flush = array( 'title' => t('Flush'), - 'href' => $uri['path'] . '/flush', - 'options' => $uri['options'], 'weight' => 200, - ); + ) + $entity->uri('flush'); return parent::getOperations($entity) + array('flush' => $flush); } diff --git a/core/modules/language/lib/Drupal/language/Entity/Language.php b/core/modules/language/lib/Drupal/language/Entity/Language.php index 6ae4385..28c0eb7 100644 --- a/core/modules/language/lib/Drupal/language/Entity/Language.php +++ b/core/modules/language/lib/Drupal/language/Entity/Language.php @@ -37,6 +37,7 @@ * "uuid" = "uuid" * }, * links = { + * "delete-form" = "language.delete", * "edit-form" = "language.edit" * } * ) diff --git a/core/modules/language/lib/Drupal/language/LanguageListController.php b/core/modules/language/lib/Drupal/language/LanguageListController.php index 9d65146..0ccffd0 100644 --- a/core/modules/language/lib/Drupal/language/LanguageListController.php +++ b/core/modules/language/lib/Drupal/language/LanguageListController.php @@ -45,16 +45,6 @@ public function getOperations(EntityInterface $entity) { $operations = parent::getOperations($entity); $default = language_default(); - // Edit and delete path for Languages entities have a different pattern - // than other config entities. - $path = 'admin/config/regional/language'; - if (isset($operations['edit'])) { - $operations['edit']['href'] = $path . '/edit/' . $entity->id(); - } - if (isset($operations['delete'])) { - $operations['delete']['href'] = $path . '/delete/' . $entity->id(); - } - // Deleting the site default language is not allowed. if ($entity->id() == $default->id) { unset($operations['delete']); diff --git a/core/modules/menu/lib/Drupal/menu/MenuListController.php b/core/modules/menu/lib/Drupal/menu/MenuListController.php index 4c5a408..aefa559 100644 --- a/core/modules/menu/lib/Drupal/menu/MenuListController.php +++ b/core/modules/menu/lib/Drupal/menu/MenuListController.php @@ -43,16 +43,13 @@ public function buildRow(EntityInterface $entity) { */ public function getOperations(EntityInterface $entity) { $operations = parent::getOperations($entity); - $uri = $entity->uri(); if (isset($operations['edit'])) { $operations['edit']['title'] = t('Edit menu'); $operations['add'] = array( 'title' => t('Add link'), - 'href' => $uri['path'] . '/add', - 'options' => $uri['options'], 'weight' => 20, - ); + ) + $entity->uri('add-form'); } if (isset($operations['delete'])) { $operations['delete']['title'] = t('Delete menu'); diff --git a/core/modules/menu/menu.module b/core/modules/menu/menu.module index 0e5ea66..8a879d7 100644 --- a/core/modules/menu/menu.module +++ b/core/modules/menu/menu.module @@ -102,6 +102,7 @@ function menu_entity_info(&$entity_info) { ->setForm('edit', 'Drupal\menu\MenuFormController') ->setForm('delete', 'Drupal\menu\Form\MenuDeleteForm') ->setList('Drupal\menu\MenuListController') + ->setLinkTemplate('add-form', 'menu.menu_add') ->setLinkTemplate('edit-form', 'menu.menu_edit'); $entity_info['menu_link'] diff --git a/core/modules/node/lib/Drupal/node/Entity/NodeType.php b/core/modules/node/lib/Drupal/node/Entity/NodeType.php index cec3461..c685430 100644 --- a/core/modules/node/lib/Drupal/node/Entity/NodeType.php +++ b/core/modules/node/lib/Drupal/node/Entity/NodeType.php @@ -37,7 +37,9 @@ * "uuid" = "uuid" * }, * links = { - * "edit-form" = "node.type_edit" + * "add-form" = "node.type_add", + * "edit-form" = "node.type_edit", + * "delete-form" = "node.type_delete_confirm" * } * ) */ diff --git a/core/modules/node/lib/Drupal/node/NodeListController.php b/core/modules/node/lib/Drupal/node/NodeListController.php index 8d488ca..8bf86aa 100644 --- a/core/modules/node/lib/Drupal/node/NodeListController.php +++ b/core/modules/node/lib/Drupal/node/NodeListController.php @@ -103,7 +103,8 @@ public function buildRow(EntityInterface $entity) { $row['title']['data'] = array( '#type' => 'link', '#title' => $entity->label(), - '#href' => $uri['path'], + '#route_name' => $uri['route_name'], + '#route_parameters' => $uri['route_parameters'], '#options' => $uri['options'] + ($langcode != Language::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? array('language' => $languages[$langcode]) : array()), '#suffix' => ' ' . drupal_render($mark), ); diff --git a/core/modules/picture/lib/Drupal/picture/Entity/PictureMapping.php b/core/modules/picture/lib/Drupal/picture/Entity/PictureMapping.php index 26a73ac..05ff927 100644 --- a/core/modules/picture/lib/Drupal/picture/Entity/PictureMapping.php +++ b/core/modules/picture/lib/Drupal/picture/Entity/PictureMapping.php @@ -35,7 +35,8 @@ * "uuid" = "uuid" * }, * links = { - * "edit-form" = "picture.mapping_page_edit" + * "edit-form" = "picture.mapping_page_edit", + * "duplicate-form" = "picture.mapping_page_duplicate" * } * ) */ diff --git a/core/modules/picture/lib/Drupal/picture/PictureMappingListController.php b/core/modules/picture/lib/Drupal/picture/PictureMappingListController.php index ffe4c0c..e690050 100644 --- a/core/modules/picture/lib/Drupal/picture/PictureMappingListController.php +++ b/core/modules/picture/lib/Drupal/picture/PictureMappingListController.php @@ -38,13 +38,10 @@ public function buildRow(EntityInterface $entity) { */ public function getOperations(EntityInterface $entity) { $operations = parent::getOperations($entity); - $uri = $entity->uri(); $operations['duplicate'] = array( 'title' => t('Duplicate'), - 'href' => $uri['path'] . '/duplicate', - 'options' => $uri['options'], 'weight' => 15, - ); + ) + $entity->uri('duplicate-form'); return $operations; } diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Entity/ShortcutSet.php b/core/modules/shortcut/lib/Drupal/shortcut/Entity/ShortcutSet.php index ef2c480..997a65e 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Entity/ShortcutSet.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Entity/ShortcutSet.php @@ -37,7 +37,8 @@ * "uuid" = "uuid" * }, * links = { - * "edit-form" = "shortcut.set_customize" + * "customize-form" = "shortcut.set_customize", + * "edit-form" = "shortcut.set_edit" * } * ) */ diff --git a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetListController.php b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetListController.php index 179992c..3be3579 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetListController.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetListController.php @@ -28,17 +28,14 @@ public function buildHeader() { */ public function getOperations(EntityInterface $entity) { $operations = parent::getOperations($entity); - $uri = $entity->uri(); if (isset($operations['edit'])) { $operations['edit']['title'] = t('Edit shortcut set'); - $operations['edit']['href'] = $uri['path'] . '/edit'; } $operations['list'] = array( 'title' => t('List links'), - 'href' => $uri['path'], - ); + ) + $entity->uri('customize-form'); return $operations; } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php index 12facd4..ca8207f 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php @@ -36,6 +36,7 @@ * "uuid" = "uuid" * }, * links = { + * "add-form" = "taxonomy.term_add", * "edit-form" = "taxonomy.overview_terms" * } * ) diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermTranslationController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermTranslationController.php index ba951a1..781d0d2 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermTranslationController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermTranslationController.php @@ -36,8 +36,7 @@ function entityFormSave(array $form, array &$form_state) { // We need a redirect here, otherwise we would get an access denied page, // since the current URL would be preserved and we would try to add a // translation for a language that already has a translation. - $uri = $entity->uri('edit-form'); - $form_state['redirect'] = $uri['path']; + $form_state['redirect_route'] = $entity->uri('edit-form'); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListController.php index ff93ede..c4fda0b 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListController.php @@ -32,25 +32,19 @@ public function getFormId() { */ public function getOperations(EntityInterface $entity) { $operations = parent::getOperations($entity); - $uri = $entity->uri(); if (isset($operations['edit'])) { $operations['edit']['title'] = t('edit vocabulary'); - $operations['edit']['href'] = $uri['path'] . '/edit'; } $operations['list'] = array( 'title' => t('list terms'), - 'href' => $uri['path'], - 'options' => $uri['options'], 'weight' => 0, - ); + ) + $entity->uri(); $operations['add'] = array( 'title' => t('add terms'), - 'href' => $uri['path'] . '/add', - 'options' => $uri['options'], 'weight' => 10, - ); + ) + $entity->uri('add-form'); unset($operations['delete']); return $operations; diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index e41b467..d2e29e7 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -388,8 +388,7 @@ function template_preprocess_taxonomy_term(&$variables) { $variables['term'] = $variables['elements']['#term']; $term = $variables['term']; - $uri = $term->uri(); - $variables['url'] = url($uri['path'], $uri['options']); + $variables['url'] = $term->url(); // We use name here because that is what appears in the UI. $variables['name'] = check_plain($term->label()); $variables['page'] = $variables['view_mode'] == 'full' && taxonomy_term_is_page($term); diff --git a/core/modules/taxonomy/taxonomy.pages.inc b/core/modules/taxonomy/taxonomy.pages.inc index 79d4472..d177e1c 100644 --- a/core/modules/taxonomy/taxonomy.pages.inc +++ b/core/modules/taxonomy/taxonomy.pages.inc @@ -19,12 +19,11 @@ function taxonomy_term_page(Term $term) { $build['#attached']['drupal_add_feed'][] = array('taxonomy/term/' . $term->id() . '/feed', 'RSS - ' . $term->label()); foreach ($term->uriRelationships() as $rel) { - $uri = $term->uri($rel); // Set the term path as the canonical URL to prevent duplicate content. $build['#attached']['drupal_add_html_head_link'][] = array( array( 'rel' => $rel, - 'href' => url($uri['path'], $uri['options']), + 'href' => $term->url($rel), ), TRUE, ); @@ -34,7 +33,7 @@ function taxonomy_term_page(Term $term) { $build['#attached']['drupal_add_html_head_link'][] = array( array( 'rel' => 'shortlink', - 'href' => url($uri['path'], array_merge($uri['options'], array('alias' => TRUE))), + 'href' => $term->url($rel, array('alias' => TRUE)), ), TRUE, ); diff --git a/core/modules/taxonomy/taxonomy.tokens.inc b/core/modules/taxonomy/taxonomy.tokens.inc index ce77a7c..eec9d73 100644 --- a/core/modules/taxonomy/taxonomy.tokens.inc +++ b/core/modules/taxonomy/taxonomy.tokens.inc @@ -112,8 +112,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = break; case 'url': - $uri = $term->uri(); - $replacements[$original] = url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE))); + $replacements[$original] = $term->url('canonical', array('absolute' => TRUE)); break; case 'node-count': diff --git a/core/modules/user/lib/Drupal/user/Entity/User.php b/core/modules/user/lib/Drupal/user/Entity/User.php index 2954df5..f9db482 100644 --- a/core/modules/user/lib/Drupal/user/Entity/User.php +++ b/core/modules/user/lib/Drupal/user/Entity/User.php @@ -44,7 +44,8 @@ * links = { * "canonical" = "user.view", * "edit-form" = "user.edit", - * "admin-form" = "user.account_settings" + * "admin-form" = "user.account_settings", + * "cancel-form" = "user.cancel" * } * ) */ diff --git a/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php b/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php index e1a3c6a..337029a 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php +++ b/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php @@ -145,7 +145,8 @@ public function buildForm(array $form, array &$form_state) { // @todo Convert to getCancelRoute() after https://drupal.org/node/1987896. $uri = $this->entity->uri(); - $form['actions']['cancel']['#href'] = $uri['path']; + $form['actions']['cancel']['#route_name'] = $uri['route_name']; + $form['actions']['cancel']['#route_parameters'] = $uri['route_parameters']; return $form; } diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/field/Link.php b/core/modules/user/lib/Drupal/user/Plugin/views/field/Link.php index 5c75d85..d4fb93b 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/field/Link.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/field/Link.php @@ -89,8 +89,7 @@ protected function renderLink(EntityInterface $entity, ResultRow $values) { $text = !empty($this->options['text']) ? $this->options['text'] : t('View'); $this->options['alter']['make_link'] = TRUE; - $uri = $entity->uri(); - $this->options['alter']['path'] = $uri['path']; + $this->options['alter'] += $entity->uri(); return $text; } diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/field/LinkCancel.php b/core/modules/user/lib/Drupal/user/Plugin/views/field/LinkCancel.php index 5d21ccf..3de5d84 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/field/LinkCancel.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/field/LinkCancel.php @@ -28,8 +28,7 @@ protected function renderLink(EntityInterface $entity, ResultRow $values) { $text = !empty($this->options['text']) ? $this->options['text'] : t('Cancel account'); - $uri = $entity->uri(); - $this->options['alter']['path'] = $uri['path'] . '/cancel'; + $this->options['alter'] += $entity->uri('cancel-form'); $this->options['alter']['query'] = drupal_get_destination(); return $text; diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/field/LinkEdit.php b/core/modules/user/lib/Drupal/user/Plugin/views/field/LinkEdit.php index 6442691..fc08b5a 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/field/LinkEdit.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/field/LinkEdit.php @@ -28,8 +28,7 @@ protected function renderLink(EntityInterface $entity, ResultRow $values) { $text = !empty($this->options['text']) ? $this->options['text'] : t('Edit'); - $uri = $entity->uri(); - $this->options['alter']['path'] = $uri['path'] . '/edit'; + $this->options['alter'] += $entity->uri('edit-form'); $this->options['alter']['query'] = drupal_get_destination(); return $text; diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/field/User.php b/core/modules/user/lib/Drupal/user/Plugin/views/field/User.php index c40f204..1b2cc35 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/field/User.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/field/User.php @@ -65,8 +65,7 @@ public function buildOptionsForm(&$form, &$form_state) { protected function renderLink($data, ResultRow $values) { if (!empty($this->options['link_to_user']) && $this->view->getUser()->hasPermission('access user profiles') && ($entity = $this->getEntity($values)) && $data !== NULL && $data !== '') { $this->options['alter']['make_link'] = TRUE; - $uri = $entity->uri(); - $this->options['alter']['path'] = $uri['path']; + $this->options['alter'] += $entity->uri(); } return $data; } diff --git a/core/modules/user/lib/Drupal/user/ProfileTranslationController.php b/core/modules/user/lib/Drupal/user/ProfileTranslationController.php index 9667170..ab206ac 100644 --- a/core/modules/user/lib/Drupal/user/ProfileTranslationController.php +++ b/core/modules/user/lib/Drupal/user/ProfileTranslationController.php @@ -36,8 +36,7 @@ function entityFormSave(array $form, array &$form_state) { // We need a redirect here, otherwise we would get an access denied page // since the current URL would be preserved and we would try to add a // translation for a language that already has a translation. - $uri = $entity->uri(); - $form_state['redirect'] = $uri['path']; + $form_state['redirect_route'] = $entity->uri(); } } } diff --git a/core/modules/user/lib/Drupal/user/RegisterFormController.php b/core/modules/user/lib/Drupal/user/RegisterFormController.php index 38612a2..137ee57 100644 --- a/core/modules/user/lib/Drupal/user/RegisterFormController.php +++ b/core/modules/user/lib/Drupal/user/RegisterFormController.php @@ -107,9 +107,8 @@ public function save(array $form, array &$form_state) { $account->password = $pass; // New administrative account without notification. - $uri = $account->uri(); if ($admin && !$notify) { - drupal_set_message($this->t('Created a new user account for %name. No e-mail has been sent.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->getUsername()))); + drupal_set_message($this->t('Created a new user account for %name. No e-mail has been sent.', array('@url' => $account->url(), '%name' => $account->getUsername()))); } // No e-mail verification required; log in user immediately. elseif (!$admin && !\Drupal::config('user.settings')->get('verify_mail') && $account->isActive()) { @@ -121,13 +120,13 @@ public function save(array $form, array &$form_state) { // No administrator approval required. elseif ($account->isActive() || $notify) { if (!$account->getEmail() && $notify) { - drupal_set_message($this->t('The new user %name was created without an email address, so no welcome message was sent.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->getUsername()))); + drupal_set_message($this->t('The new user %name was created without an email address, so no welcome message was sent.', array('@url' => $account->url(), '%name' => $account->getUsername()))); } else { $op = $notify ? 'register_admin_created' : 'register_no_approval_required'; if (_user_mail_notify($op, $account)) { if ($notify) { - drupal_set_message($this->t('A welcome message with further instructions has been e-mailed to the new user %name.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->getUsername()))); + drupal_set_message($this->t('A welcome message with further instructions has been e-mailed to the new user %name.', array('@url' => $account->url(), '%name' => $account->getUsername()))); } else { drupal_set_message($this->t('A welcome message with further instructions has been sent to your e-mail address.')); diff --git a/core/modules/user/lib/Drupal/user/RoleFormController.php b/core/modules/user/lib/Drupal/user/RoleFormController.php index 01076dd..17f376f 100644 --- a/core/modules/user/lib/Drupal/user/RoleFormController.php +++ b/core/modules/user/lib/Drupal/user/RoleFormController.php @@ -69,11 +69,11 @@ public function save(array $form, array &$form_state) { $uri = $entity->uri(); if ($entity->save() == SAVED_UPDATED) { drupal_set_message($this->t('Role %label has been updated.', array('%label' => $entity->label()))); - watchdog('user', 'Role %label has been updated.', array('%label' => $entity->label()), WATCHDOG_NOTICE, l($this->t('Edit'), $uri['path'])); + watchdog('user', 'Role %label has been updated.', array('%label' => $entity->label()), WATCHDOG_NOTICE, \Drupal::l($this->t('Edit'), $uri['route_name'], $uri['parameters'], $uri['options'])); } else { drupal_set_message($this->t('Role %label has been added.', array('%label' => $entity->label()))); - watchdog('user', 'Role %label has been added.', array('%label' => $entity->label()), WATCHDOG_NOTICE, l($this->t('Edit'), $uri['path'])); + watchdog('user', 'Role %label has been added.', array('%label' => $entity->label()), WATCHDOG_NOTICE, \Drupal::l($this->t('Edit'), $uri['route_name'], $uri['parameters'], $uri['options'])); } $form_state['redirect_route']['route_name'] = 'user.role_list'; } diff --git a/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php b/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php index 76bf0e9..13c6806 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php @@ -52,7 +52,6 @@ function testLabelCallback() { * Test URI callback. */ function testUriCallback() { - $uri = $this->account->uri(); - $this->assertEqual('user/' . $this->account->id(), $uri['path'], 'Correct user URI.'); + $this->assertEqual('user/' . $this->account->id(), $this->account->url(), 'Correct user URI.'); } } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/field/EntityLabel.php b/core/modules/views/lib/Drupal/views/Plugin/views/field/EntityLabel.php index 7ac209b..efb965a 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/field/EntityLabel.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/field/EntityLabel.php @@ -109,9 +109,8 @@ public function render(ResultRow $values) { $entity = $this->loadedReferencers[$type][$value]; if (!empty($this->options['link_to_entity'])) { - $uri = $entity->uri(); $this->options['alter']['make_link'] = TRUE; - $this->options['alter']['path'] = $uri['path']; + $this->options['alter'] += $entity->uri(); } return $this->sanitizeValue($entity->label()); diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewCloneFormController.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewCloneFormController.php index 4071738..69bee05 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewCloneFormController.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewCloneFormController.php @@ -72,8 +72,7 @@ public function submit(array $form, array &$form_state) { $this->entity->save(); // Redirect the user to the view admin form. - $uri = $this->entity->uri(); - $form_state['redirect'] = $uri['path']; + $form_state['redirect_route'] = $this->entity->uri('edit-form'); return $this->entity; } diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewListController.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewListController.php index b45efe7..052bde0 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewListController.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewListController.php @@ -140,14 +140,13 @@ public function buildHeader() { */ public function getOperations(EntityInterface $entity) { $operations = parent::getOperations($entity); - $uri = $entity->uri(); - $operations['clone'] = array( - 'title' => $this->t('Clone'), - 'href' => $uri['path'] . '/clone', - 'options' => $uri['options'], - 'weight' => 15, - ); + if ($this->entityInfo->hasLinkTemplate('clone')) { + $operations['clone'] = array( + 'title' => $this->t('Clone'), + 'weight' => 15, + ) + $entity->uri('clone'); + } // Add AJAX functionality to enable/disable operations. foreach (array('enable', 'disable') as $op) { diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php index ea6448c..51dc4ec 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -890,8 +890,8 @@ public function save() { /** * Implements \Drupal\Core\Entity\EntityInterface::uri(). */ - public function uri() { - return $this->storage->uri(); + public function uri($rel = 'canonical') { + return $this->storage->uri($rel); } /** @@ -1171,4 +1171,8 @@ public function changed() { return $this->storage->changed(); } + public function url($rel = 'canonical', $options = array()) { + // TODO: Implement url() method. + } + } diff --git a/core/modules/views_ui/views_ui.module b/core/modules/views_ui/views_ui.module index 5afbfc5..4dd0b92 100644 --- a/core/modules/views_ui/views_ui.module +++ b/core/modules/views_ui/views_ui.module @@ -73,7 +73,8 @@ function views_ui_entity_info(&$entity_info) { ->setForm('delete', 'Drupal\views_ui\ViewDeleteFormController') ->setForm('break_lock', 'Drupal\views_ui\Form\BreakLockForm') ->setList('Drupal\views_ui\ViewListController') - ->setLinkTemplate('edit-form', 'views_ui.edit'); + ->setLinkTemplate('edit-form', 'views_ui.edit') + ->setLinkTemplate('clone', 'views_ui.clone'); } /**