From be3b019856457745b1cb3fe826a9ee2e9a343274 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 29 Nov 2024 14:59:02 +1000
Subject: [PATCH] Issue #2699959 by quietone, dragos-dumi, smustgrave,
 larowlan, joachim: Update link templates of test entities

---
 .../Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php | 6 +-----
 .../tests/modules/entity_test/src/Entity/EntityTest.php     | 3 ++-
 .../modules/entity_test/src/Entity/EntityTestAddPage.php    | 2 +-
 .../modules/entity_test/src/Entity/EntityTestMulChanged.php | 3 ++-
 .../entity_test/src/Entity/EntityTestMulLangcodeKey.php     | 3 ++-
 .../modules/entity_test/src/Entity/EntityTestMulRev.php     | 3 ++-
 .../entity_test/src/Entity/EntityTestMulRevChanged.php      | 3 ++-
 .../modules/entity_test/src/Entity/EntityTestMulRevPub.php  | 3 ++-
 .../tests/modules/entity_test/src/Entity/EntityTestNoId.php | 3 ++-
 .../tests/modules/entity_test/src/Entity/EntityTestRev.php  | 3 ++-
 .../modules/entity_test/src/Entity/EntityTestRevPub.php     | 1 +
 .../modules/entity_test/src/Entity/EntityTestStringId.php   | 3 ++-
 .../modules/entity_test/src/Entity/EntityTestUuidId.php     | 3 ++-
 13 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php b/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php
index c3eccbe7b1b4..dc460ed70f26 100644
--- a/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php
+++ b/core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php
@@ -154,11 +154,7 @@ protected function getAddFormRoute(EntityTypeInterface $entity_type) {
 
       // If the entity has bundles, we can provide a bundle-specific title
       // and access requirements.
-      $expected_parameter = $entity_type->getBundleEntityType() ?: $entity_type->getKey('bundle');
-      // @todo We have to check if a route contains a bundle in its path as
-      //   test entities have inconsistent usage of "add-form" link templates.
-      //   Fix it in https://www.drupal.org/node/2699959.
-      if (($bundle_key = $entity_type->getKey('bundle')) && str_contains($route->getPath(), '{' . $expected_parameter . '}')) {
+      if ($bundle_key = $entity_type->getKey('bundle')) {
         $route->setDefault('_title_callback', EntityController::class . '::addBundleTitle');
         // If the bundles are entities themselves, we can add parameter
         // information to the route options.
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php
index 2afedb543ef3..9c7298121a0c 100644
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php
@@ -47,7 +47,8 @@
   ],
   links: [
     'canonical' => '/entity_test/{entity_test}',
-    'add-form' => '/entity_test/add',
+    'add-form' => '/entity_test/add/{type}',
+    'add-page' => '/entity_test/add',
     'edit-form' => '/entity_test/manage/{entity_test}/edit',
     'delete-form' => '/entity_test/delete/entity_test/{entity_test}',
   ],
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestAddPage.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestAddPage.php
index da2226e32e77..b73e198ef93f 100644
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestAddPage.php
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestAddPage.php
@@ -32,7 +32,7 @@
   ],
   links: [
     'add-page' => '/entity_test_add_page/{user}/add',
-    'add-form' => '/entity_test_add_page/add/{user}/form',
+    'add-form' => '/entity_test_add_page/add/{type}/{user}/form',
   ],
   admin_permission: 'administer entity_test content',
   base_table: 'entity_test_add_page',
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulChanged.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulChanged.php
index bfb0f6b10ade..6ffeadde9073 100644
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulChanged.php
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulChanged.php
@@ -43,7 +43,8 @@
     'views_data' => EntityViewsData::class,
   ],
   links: [
-    'add-form' => '/entity_test_mul_changed/add',
+    'add-form' => '/entity_test_mul_changed/add/{type}',
+    'add-page' => '/entity_test_mul_changed/add',
     'canonical' => '/entity_test_mul_changed/manage/{entity_test_mul_changed}',
     'edit-form' => '/entity_test_mul_changed/manage/{entity_test_mul_changed}/edit',
     'delete-form' => '/entity_test/delete/entity_test_mul_changed/{entity_test_mul_changed}',
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulLangcodeKey.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulLangcodeKey.php
index a536f72bcd4f..5c7ab4e80b99 100644
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulLangcodeKey.php
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulLangcodeKey.php
@@ -40,7 +40,8 @@
     ],
   ],
   links: [
-    'add-form' => '/entity_test_mul_langcode_key/add',
+    'add-form' => '/entity_test_mul_langcode_key/add/{type}',
+    'add-page' => '/entity_test_mul_langcode_key/add',
     'canonical' => '/entity_test_mul_langcode_key/manage/{entity_test_mul_langcode_key}',
     'edit-form' => '/entity_test_mul_langcode_key/manage/{entity_test_mul_langcode_key}/edit',
     'delete-form' => '/entity_test/delete/entity_test_mul_langcode_key/{entity_test_mul_langcode_key}',
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRev.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRev.php
index 58e0072e0fd7..ab28719c20a3 100644
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRev.php
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRev.php
@@ -40,7 +40,8 @@
     'route_provider' => ['html' => DefaultHtmlRouteProvider::class],
   ],
   links: [
-    'add-form' => '/entity_test_mulrev/add',
+    'add-form' => '/entity_test_mulrev/add/{type}',
+    'add-page' => '/entity_test_mulrev/add',
     'canonical' => '/entity_test_mulrev/manage/{entity_test_mulrev}',
     'delete-form' => '/entity_test/delete/entity_test_mulrev/{entity_test_mulrev}',
     'edit-form' => '/entity_test_mulrev/manage/{entity_test_mulrev}/edit',
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRevChanged.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRevChanged.php
index e88e6714e637..6824b1d84064 100644
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRevChanged.php
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRevChanged.php
@@ -42,7 +42,8 @@
     'views_data' => EntityViewsData::class,
   ],
   links: [
-    'add-form' => '/entity_test_mulrev_changed/add',
+    'add-form' => '/entity_test_mulrev_changed/add/{type}',
+    'add-page' => '/entity_test_mulrev_changed/add',
     'canonical' => '/entity_test_mulrev_changed/manage/{entity_test_mulrev_changed}',
     'delete-form' => '/entity_test/delete/entity_test_mulrev_changed/{entity_test_mulrev_changed}',
     'edit-form' => '/entity_test_mulrev_changed/manage/{entity_test_mulrev_changed}/edit',
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRevPub.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRevPub.php
index 412c60e9ae91..20faeb58d4f3 100644
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRevPub.php
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulRevPub.php
@@ -46,7 +46,8 @@
     ],
   ],
   links: [
-    'add-form' => '/entity_test_mulrevpub/add',
+    'add-form' => '/entity_test_mulrevpub/add/{type}',
+    'add-page' => '/entity_test_mulrevpub/add',
     'canonical' => '/entity_test_mulrevpub/manage/{entity_test_mulrevpub}',
     'delete-form' => '/entity_test/delete/entity_test_mulrevpub/{entity_test_mulrevpub}',
     'delete-multiple-form' => '/entity_test/delete',
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestNoId.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestNoId.php
index 7382b31a5535..eb6a5649fe9e 100644
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestNoId.php
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestNoId.php
@@ -21,7 +21,8 @@
     'storage' => ContentEntityNullStorage::class,
   ],
   links: [
-    'add-form' => '/entity_test_no_id/add',
+    'add-form' => '/entity_test_no_id/add/{type}',
+    'add-page' => '/entity_test_no_id/add',
   ],
   admin_permission: 'administer entity_test content',
   field_ui_base_route: 'entity.entity_test_no_id.admin_form',
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRev.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRev.php
index 1aa90d50d301..7f4f25572e91 100644
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRev.php
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRev.php
@@ -50,7 +50,8 @@
     ],
   ],
   links: [
-    'add-form' => '/entity_test_rev/add',
+    'add-form' => '/entity_test_rev/add/{type}',
+    'add-page' => '/entity_test_rev/add',
     'canonical' => '/entity_test_rev/manage/{entity_test_rev}',
     'delete-form' => '/entity_test/delete/entity_test_rev/{entity_test_rev}',
     'delete-multiple-form' => '/entity_test_rev/delete_multiple',
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRevPub.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRevPub.php
index 877710005c05..6b8d97f96ffc 100644
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRevPub.php
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestRevPub.php
@@ -51,6 +51,7 @@
   ],
   links: [
     'add-form' => '/entity_test_revpub/add',
+    'add-page' => '/entity_test_revpub/add/{type}',
     'canonical' => '/entity_test_revpub/manage/{entity_test_revpub}',
     'delete-form' => '/entity_test/delete/entity_test_revpub/{entity_test_revpub}',
     'delete-multiple-form' => '/entity_test_revpub/delete_multiple',
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestStringId.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestStringId.php
index 2db1fe8bc019..9dd9d010ef7c 100644
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestStringId.php
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestStringId.php
@@ -35,7 +35,8 @@
   ],
   links: [
     'canonical' => '/entity_test_string_id/manage/{entity_test_string_id}',
-    'add-form' => '/entity_test_string_id/add',
+    'add-form' => '/entity_test_string_id/add/{type}',
+    'add-page' => '/entity_test_string_id/add',
     'edit-form' => '/entity_test_string_id/manage/{entity_test_string_id}',
   ],
   admin_permission: 'administer entity_test content',
diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestUuidId.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestUuidId.php
index 5935fd857ded..2385612cd465 100644
--- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestUuidId.php
+++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestUuidId.php
@@ -37,7 +37,8 @@
  *   },
  *   links = {
  *     "canonical" = "/entity_test_uuid_id/manage/{entity_test_uuid_id}",
- *     "add-form" = "/entity_test_uuid_id/add",
+ *     "add-form" = "/entity_test_uuid_id/add/{type}",
+ *     "add-page" = "/entity_test_uuid_id/add",
  *     "edit-form" = "/entity_test_uuid_id/manage/{entity_test_uuid_id}/edit",
  *   },
  * )
-- 
GitLab