diff --git a/core/lib/Drupal/Core/Entity/Routing/AdminHtmlRouteProvider.php b/core/lib/Drupal/Core/Entity/Routing/AdminHtmlRouteProvider.php index 382545d..4e6c197 100644 --- a/core/lib/Drupal/Core/Entity/Routing/AdminHtmlRouteProvider.php +++ b/core/lib/Drupal/Core/Entity/Routing/AdminHtmlRouteProvider.php @@ -17,19 +17,21 @@ class AdminHtmlRouteProvider extends DefaultHtmlRouteProvider { /** * {@inheritdoc} */ - public function getRoutes(EntityTypeInterface $entity_type) { - $collection = parent::getRoutes($entity_type); - - $entity_type_id = $entity_type->id(); - - if ($route = $collection->get("entity.{$entity_type_id}.edit_form")) { + protected function getEditFormRoute(EntityTypeInterface $entity_type) { + if ($route = parent::getEditFormRoute($entity_type)) { $route->setOption('_admin_route', TRUE); + return $route; } - if ($route = $collection->get("entity.{$entity_type_id}.delete_form")) { + } + + /** + * {@inheritdoc} + */ + protected function getDeleteFormRoute(EntityTypeInterface $entity_type) { + if ($route = parent::getEditFormRoute($entity_type)) { $route->setOption('_admin_route', TRUE); + return $route; } - - return $collection; } } diff --git a/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php b/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php index 80cbc51..fac1598 100644 --- a/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php +++ b/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php @@ -29,7 +29,33 @@ public function getRoutes(EntityTypeInterface $entity_type) { $entity_type_id = $entity_type->id(); - if ($entity_type->hasLinkTemplate('canonical')) { + if ($route = $this->getCanonicalRoute($entity_type)) { + $collection->add("entity.{$entity_type_id}.canonical", $route); + } + + if ($route = $this->getEditFormRoute($entity_type)) { + $collection->add("entity.{$entity_type_id}.edit_form", $route); + } + + if ($route = $this->getDeleteFormRoute($entity_type)) { + $collection->add("entity.{$entity_type_id}.delete_form", $route); + } + + return $collection; + } + + /** + * Gets the canonical route. + * + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type. + * + * @return \Symfony\Component\Routing\Route|null + * The generated route, if available. + */ + protected function getCanonicalRoute(EntityTypeInterface $entity_type) { + if ($entity_type->hasLinkTemplate('canonical') && $entity_type->hasViewBuilderClass()) { + $entity_type_id = $entity_type->id(); $route = (new Route($entity_type->getLinkTemplate('canonical'))); $route ->addDefaults([ @@ -40,10 +66,22 @@ public function getRoutes(EntityTypeInterface $entity_type) { ->setOption('parameters', [ $entity_type_id => ['type' => 'entity:' . $entity_type_id], ]); - $collection->add("entity.{$entity_type_id}.canonical", $route); + return $route; } + } + /** + * Gets the edit-form route. + * + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type. + * + * @return \Symfony\Component\Routing\Route|null + * The generated route, if available. + */ + protected function getEditFormRoute(EntityTypeInterface $entity_type) { if ($entity_type->hasLinkTemplate('edit-form')) { + $entity_type_id = $entity_type->id(); $route = (new Route($entity_type->getLinkTemplate('edit-form'))); // Use the "edit" form handler, otherwise default. $operation = 'default'; @@ -59,10 +97,22 @@ public function getRoutes(EntityTypeInterface $entity_type) { ->setOption('parameters', [ $entity_type_id => ['type' => 'entity:' . $entity_type_id], ]); - $collection->add("entity.{$entity_type_id}.edit_form", $route); + return $route; } + } + /** + * Gets the delete-form route. + * + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type. + * + * @return \Symfony\Component\Routing\Route|null + * The generated route, if available. + */ + protected function getDeleteFormRoute(EntityTypeInterface $entity_type) { if ($entity_type->hasLinkTemplate('delete-form')) { + $entity_type_id = $entity_type->id(); $route = (new Route($entity_type->getLinkTemplate('delete-form'))); $route ->addDefaults([ @@ -73,10 +123,8 @@ public function getRoutes(EntityTypeInterface $entity_type) { ->setOption('parameters', [ $entity_type_id => ['type' => 'entity:' . $entity_type_id], ]); - $collection->add("entity.{$entity_type_id}.delete_form", $route); + return $route; } - - return $collection; } } diff --git a/core/lib/Drupal/Core/EventSubscriber/EntityRouteProviderSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/EntityRouteProviderSubscriber.php index d5c4def..9674bf3 100644 --- a/core/lib/Drupal/Core/EventSubscriber/EntityRouteProviderSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/EntityRouteProviderSubscriber.php @@ -48,12 +48,14 @@ public function onDynamicRouteEvent(RouteBuildEvent $event) { foreach ($this->entityManager->getRouteProviders($entity_type->id()) as $route_provider) { // Allow to both return an array of routes or a route collection, // like route_callbacks in the routing.yml file. + $routes = $route_provider->getRoutes($entity_type); if ($routes instanceof RouteCollection) { - $route_collection->addCollection($routes); + $routes = $routes->all(); } - elseif (is_array($routes)) { - foreach ($routes as $route_name => $route) { + foreach ($routes as $route_name => $route) { + // Don't override static defined routes. + if (!$route_collection->get($route_name)) { $route_collection->add($route_name, $route); } } diff --git a/core/modules/aggregator/src/FeedHtmlRouteProvider.php b/core/modules/aggregator/src/FeedHtmlRouteProvider.php index fd9f900..6ccfa7c 100644 --- a/core/modules/aggregator/src/FeedHtmlRouteProvider.php +++ b/core/modules/aggregator/src/FeedHtmlRouteProvider.php @@ -18,13 +18,12 @@ class FeedHtmlRouteProvider extends AdminHtmlRouteProvider { /** * {@inheritdoc} */ - public function getRoutes(EntityTypeInterface $entity_type) { - $collection = parent::getRoutes($entity_type); + protected function getEditFormRoute(EntityTypeInterface $entity_type) { + $route = parent::getEditFormRoute($entity_type); - $collection->get('entity.aggregator_feed.edit_form') - ->setDefault('_title', 'Configure'); + $route->setDefault('_title', 'Configure'); - return $collection; + return $route; } } diff --git a/core/modules/comment/src/CommentHtmlRouteProvider.php b/core/modules/comment/src/CommentHtmlRouteProvider.php index 1310a31..d2d3c66 100644 --- a/core/modules/comment/src/CommentHtmlRouteProvider.php +++ b/core/modules/comment/src/CommentHtmlRouteProvider.php @@ -17,16 +17,15 @@ class CommentHtmlRouteProvider extends DefaultHtmlRouteProvider { /** * {@inheritdoc} */ - public function getRoutes(EntityTypeInterface $entity_type) { - $collection = parent::getRoutes($entity_type); + protected function getCanonicalRoute(EntityTypeInterface $entity_type) { + $route = parent::getCanonicalRoute($entity_type); - $collection->get('entity.comment.canonical') - ->setDefaults([ - '_title_callback' => '\Drupal\comment\Controller\CommentController::commentPermalinkTitlek', - '_controller' => '\Drupal\comment\Controller\CommentController::commentPermalink', - ]); + $route->setDefaults([ + '_title_callback' => '\Drupal\comment\Controller\CommentController::commentPermalinkTitle', + '_controller' => '\Drupal\comment\Controller\CommentController::commentPermalink', + ]); - return $collection; + return $route; } } diff --git a/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php b/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php index bf781fb..1b99552 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php @@ -56,8 +56,6 @@ protected function doTestBasicTranslation() { $this->entityId = $this->createEntity($values[$default_langcode], $default_langcode); $entity = entity_load($this->entityTypeId, $this->entityId, TRUE); $this->assertTrue($entity, 'Entity found in the database.'); - $this->drupalGet($entity->urlInfo()); - $this->assertResponse(200, 'Entity URL is valid.'); $this->drupalGet($entity->urlInfo('drupal:content-translation-overview')); $this->assertNoText('Source language', 'Source language column correctly hidden.'); diff --git a/core/modules/forum/src/Tests/ForumTest.php b/core/modules/forum/src/Tests/ForumTest.php index 451a28a..9440179 100644 --- a/core/modules/forum/src/Tests/ForumTest.php +++ b/core/modules/forum/src/Tests/ForumTest.php @@ -286,7 +286,7 @@ private function doAdminTests($user) { // Add forum to the Tools menu. $edit = array(); - $this->drupalPostForm('admin/structure/menu/manage/tools/edit', $edit, t('Save')); + $this->drupalPostForm('admin/structure/menu/manage/tools', $edit, t('Save')); $this->assertResponse(200); // Edit forum taxonomy. @@ -322,7 +322,7 @@ private function doAdminTests($user) { $this->rootForum = $this->createForum('forum'); // Test vocabulary form alterations. - $this->drupalGet('admin/structure/taxonomy/manage/forums/edit'); + $this->drupalGet('admin/structure/taxonomy/manage/forums'); $this->assertFieldByName('op', t('Save'), 'Save button found.'); $this->assertNoFieldByName('op', t('Delete'), 'Delete button not found.'); @@ -343,7 +343,7 @@ private function doAdminTests($user) { )); $vocabulary->save(); // Test tags vocabulary form is not affected. - $this->drupalGet('admin/structure/taxonomy/manage/tags/edit'); + $this->drupalGet('admin/structure/taxonomy/manage/tags'); $this->assertFieldByName('op', t('Save'), 'Save button found.'); $this->assertLink(t('Delete')); // Test tags vocabulary term form is not affected. @@ -369,7 +369,7 @@ function editForumVocabulary() { ); // Edit the vocabulary. - $this->drupalPostForm($original_vocabulary->urlInfo('edit-form'), $edit, t('Save')); + $this->drupalPostForm('admin/structure/taxonomy/manage/' . $original_vocabulary->id(), $edit, t('Save')); $this->assertResponse(200); $this->assertRaw(t('Updated vocabulary %name.', array('%name' => $edit['name'])), 'Vocabulary was edited'); diff --git a/core/modules/menu_link_content/src/Tests/MenuLinkContentTranslationUITest.php b/core/modules/menu_link_content/src/Tests/MenuLinkContentTranslationUITest.php index b068808..8dc4421 100644 --- a/core/modules/menu_link_content/src/Tests/MenuLinkContentTranslationUITest.php +++ b/core/modules/menu_link_content/src/Tests/MenuLinkContentTranslationUITest.php @@ -90,7 +90,7 @@ function testTranslationLinkTheme() { $this->drupalPostForm('admin/appearance', $edit, t('Save configuration')); $this->drupalGet('admin/structure/menu/item/' . $entityId . '/edit'); $this->assertRaw('core/themes/seven/css/base/elements.css', 'Edit uses admin theme.'); - $this->drupalGet('admin/structure/menu/item/' . $entityId . '/edit/translations'); + $this->drupalGet('admin/structure/menu/item/' . $entityId . '/translations'); $this->assertRaw('core/themes/seven/css/base/elements.css', 'Translation uses admin theme as well.'); } diff --git a/core/modules/rest/src/Tests/AuthTest.php b/core/modules/rest/src/Tests/AuthTest.php index 04a307d..c222b26 100644 --- a/core/modules/rest/src/Tests/AuthTest.php +++ b/core/modules/rest/src/Tests/AuthTest.php @@ -96,7 +96,6 @@ protected function basicAuthGet(Url $url, $username, $password, $mime_type = NUL CURLOPT_URL => $url->setAbsolute()->toString(), CURLOPT_NOBODY => FALSE, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, - CURLOPT_HTTPHEADER => array('Accept: ' . $this->defaultMimeType), CURLOPT_USERPWD => $username . ':' . $password, CURLOPT_HTTPHEADER => array('Accept: ' . $mime_type), ) diff --git a/core/modules/rest/src/Tests/ResourceTest.php b/core/modules/rest/src/Tests/ResourceTest.php index aa8e9b4..102baf5 100644 --- a/core/modules/rest/src/Tests/ResourceTest.php +++ b/core/modules/rest/src/Tests/ResourceTest.php @@ -87,6 +87,8 @@ public function testAuthentication() { $this->config->save(); $this->rebuildCache(); + $account = $this->drupalCreateUser(['view test entity']); + \Drupal::service('account_switcher')->switchTo($account); // Verify that accessing the resource returns 401. $response = $this->httpRequest($this->entity->urlInfo(), 'GET', NULL, $this->defaultMimeType); // AcceptHeaderMatcher considers the canonical, non-REST route a match, but diff --git a/core/modules/system/src/Tests/Menu/BreadcrumbTest.php b/core/modules/system/src/Tests/Menu/BreadcrumbTest.php index ca569b4..456ff5e 100644 --- a/core/modules/system/src/Tests/Menu/BreadcrumbTest.php +++ b/core/modules/system/src/Tests/Menu/BreadcrumbTest.php @@ -79,7 +79,7 @@ function testBreadCrumbs() { $trail += array( 'admin/structure/taxonomy' => t('Taxonomy'), ); - $this->assertBreadcrumb('admin/structure/taxonomy/manage/tags/edit', $trail); + $this->assertBreadcrumb('admin/structure/taxonomy/manage/tags', $trail); $trail += array( 'admin/structure/taxonomy/manage/tags' => t('Tags'), ); @@ -95,7 +95,7 @@ function testBreadCrumbs() { $trail += array( 'admin/structure/menu' => t('Menus'), ); - $this->assertBreadcrumb('admin/structure/menu/manage/tools/edit', $trail); + $this->assertBreadcrumb('admin/structure/menu/manage/tools', $trail); $trail += array( 'admin/structure/menu/manage/tools' => t('Tools'), @@ -109,7 +109,7 @@ function testBreadCrumbs() { 'admin/structure/types' => t('Content types'), ); $this->assertBreadcrumb('admin/structure/types/add', $trail); - $this->assertBreadcrumb("admin/structure/types/manage/$type/edit", $trail); + $this->assertBreadcrumb("admin/structure/types/manage/$type", $trail); $trail += array( "admin/structure/types/manage/$type" => t('Article'), ); diff --git a/core/modules/system/tests/modules/entity_test/entity_test.routing.yml b/core/modules/system/tests/modules/entity_test/entity_test.routing.yml index 6f9a7a4..ebe5579 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.routing.yml +++ b/core/modules/system/tests/modules/entity_test/entity_test.routing.yml @@ -1,3 +1,11 @@ +entity.entity_test.canonical: + path: '/entity_test/{entity_test}' + defaults: + _entity_view: 'entity_test.full' + _title: 'Test full view mode' + requirements: + _access: 'TRUE' + entity.entity_test.render_options: path: '/entity_test_converter/{foo}' options: diff --git a/core/modules/taxonomy/src/Controller/TaxonomyController.php b/core/modules/taxonomy/src/Controller/TaxonomyController.php index 95c387e..e24eb6f 100644 --- a/core/modules/taxonomy/src/Controller/TaxonomyController.php +++ b/core/modules/taxonomy/src/Controller/TaxonomyController.php @@ -47,6 +47,19 @@ public function addForm(VocabularyInterface $taxonomy_vocabulary) { /** * Route title callback. * + * @param \Drupal\taxonomy\VocabularyInterface $taxonomy_vocabulary + * The taxonomy term. + * + * @return string + * The term label. + */ + public function vocabularyTitle(VocabularyInterface $taxonomy_vocabulary) { + return Xss::filter($taxonomy_vocabulary->label()); + } + + /** + * Route title callback. + * * @param \Drupal\taxonomy\TermInterface $taxonomy_term * The taxonomy term. * diff --git a/core/modules/taxonomy/src/Entity/Vocabulary.php b/core/modules/taxonomy/src/Entity/Vocabulary.php index d65d0b3..fb2f3f2 100644 --- a/core/modules/taxonomy/src/Entity/Vocabulary.php +++ b/core/modules/taxonomy/src/Entity/Vocabulary.php @@ -26,7 +26,7 @@ * "delete" = "Drupal\taxonomy\Form\VocabularyDeleteForm" * }, * "route_provider" = { - * "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider", + * "html" = "Drupal\taxonomy\Entity\VocabularyRouteProvider", * }, * }, * admin_permission = "administer taxonomy", @@ -40,7 +40,7 @@ * links = { * "canonical" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}", * "add-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/add", - * "edit-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/edit", + * "edit-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}", * "delete-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/delete", * "reset-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/reset", * "overview-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/overview", diff --git a/core/modules/views_ui/src/ViewHtmlRouteProvider.php b/core/modules/views_ui/src/ViewHtmlRouteProvider.php index 61bdf83..6559a74 100644 --- a/core/modules/views_ui/src/ViewHtmlRouteProvider.php +++ b/core/modules/views_ui/src/ViewHtmlRouteProvider.php @@ -19,16 +19,16 @@ class ViewHtmlRouteProvider extends DefaultHtmlRouteProvider { /** * {@inheritdoc} */ - public function getRoutes(EntityTypeInterface $entity_type) { - $collection = parent::getRoutes($entity_type); + protected function getEditFormRoute(EntityTypeInterface $entity_type) { + $route = parent::getEditFormRoute($entity_type); - $collection->get('entity.view.edit_form') - // Replace the _entity_form with a custom _controller. + // Replace the _entity_form with a custom _controller. + $route ->setDefault('_entity_form', NULL) ->setDefault('_controller', '\Drupal\views_ui\Controller\ViewsUIController::edit') ->setOptions(['parameters' => ['view' => ['tempstore' => TRUE, 'type' => 'entity:view']]]); - return $collection; + return $route; } }