diff --git a/core/modules/system/tests/modules/entity_test/src/Controller/EntityTestEntityController.php b/core/modules/system/tests/modules/entity_test/src/Controller/EntityTestEntityController.php new file mode 100644 index 0000000000000000000000000000000000000000..823cea9582708627fe033023477d77aa6c4d6179 --- /dev/null +++ b/core/modules/system/tests/modules/entity_test/src/Controller/EntityTestEntityController.php @@ -0,0 +1,30 @@ +<?php + +namespace Drupal\entity_test\Controller; + +use Drupal\Core\Entity\Controller\EntityController; +use Symfony\Component\HttpFoundation\Response; + +/** + * Controller for test entities based on the core EntityController. + */ +class EntityTestEntityController extends EntityController { + + /** + * {@inheritdoc} + */ + public function addPage($entity_type_id) { + $response = parent::addPage($entity_type_id); + + if ($response instanceof Response) { + return $response; + } + foreach ($response['#bundles'] as $bundle) { + $bundle['add_link']->getUrl()->setOption('attributes', [ + 'class' => ['bundle-link'], + ]); + } + return $response; + } + +} diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestWithBundle.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestWithBundle.php index c668bd3ee80bc655d1243c423c15c6ba9ac5b299..57a7a730808d4f2eddc58f7a28f6b5c0a9d7677c 100644 --- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestWithBundle.php +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestWithBundle.php @@ -21,7 +21,7 @@ * "delete" = "\Drupal\Core\Entity\EntityDeleteForm" * }, * "route_provider" = { - * "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider", + * "html" = "Drupal\entity_test\Routing\HtmlRouteProvider", * }, * }, * base_table = "entity_test_with_bundle", diff --git a/core/modules/system/tests/modules/entity_test/src/Routing/HtmlRouteProvider.php b/core/modules/system/tests/modules/entity_test/src/Routing/HtmlRouteProvider.php new file mode 100644 index 0000000000000000000000000000000000000000..475cd34d286b75b48d9929ccc2d8adcbb51eb9ca --- /dev/null +++ b/core/modules/system/tests/modules/entity_test/src/Routing/HtmlRouteProvider.php @@ -0,0 +1,23 @@ +<?php + +namespace Drupal\entity_test\Routing; + +use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider; +use Drupal\entity_test\Controller\EntityTestEntityController; + +/** + * Route provider for test entities. + */ +class HtmlRouteProvider extends DefaultHtmlRouteProvider { + + /** + * {@inheritdoc} + */ + protected function getAddPageRoute(EntityTypeInterface $entity_type) { + return parent::getAddPageRoute($entity_type) + ->setDefault('_controller', EntityTestEntityController::class . '::addPage') + ->setOption('_admin_route', TRUE); + } + +} diff --git a/core/modules/system/tests/src/Functional/SevenBundleAddPageLinkAttributesTest.php b/core/modules/system/tests/src/Functional/SevenBundleAddPageLinkAttributesTest.php new file mode 100644 index 0000000000000000000000000000000000000000..3a200a929ccad235e1d51218539cca6ed9a144fc --- /dev/null +++ b/core/modules/system/tests/src/Functional/SevenBundleAddPageLinkAttributesTest.php @@ -0,0 +1,46 @@ +<?php + +namespace Drupal\Tests\system\Functional; + +use Drupal\entity_test\Entity\EntityTestBundle; +use Drupal\Tests\BrowserTestBase; + +/** + * Tests Seven's handling of link attributes on multi-bundle entity add page. + * + * @group system + */ +class SevenBundleAddPageLinkAttributesTest extends BrowserTestBase { + + /** + * {@inheritdoc} + */ + public static $modules = ['entity_test']; + + /** + * {@inheritdoc} + */ + protected $profile = 'standard'; + + /** + * Tests that Seven preserves attributes in multi-bundle entity add links. + */ + public function testSevenBundleAddPageLinkAttributes() { + $account = $this->drupalCreateUser(['administer entity_test_with_bundle content']); + $this->drupalLogin($account); + + $this->config('system.theme')->set('default', 'seven')->save(); + + for ($i = 0; $i < 2; $i++) { + EntityTestBundle::create([ + 'id' => $this->randomMachineName(), + 'label' => $this->randomString(), + 'description' => $this->randomString(), + ])->save(); + } + + $this->drupalGet('/entity_test_with_bundle/add'); + $this->assertSession()->elementExists('css', 'a.bundle-link'); + } + +} diff --git a/core/themes/seven/templates/entity-add-list.html.twig b/core/themes/seven/templates/entity-add-list.html.twig index 3ff2e717df64475f3399bf3be74b6c3831108480..f00ecd1fc2fbe499b712d9611af317a3a0840358 100644 --- a/core/themes/seven/templates/entity-add-list.html.twig +++ b/core/themes/seven/templates/entity-add-list.html.twig @@ -17,7 +17,7 @@ {% if bundles is not empty %} <ul class="admin-list"> {% for bundle in bundles %} - <li class="clearfix"><a href="{{ bundle.add_link.url }}"><span class="label">{{ bundle.label }}</span><div class="description">{{ bundle.description }}</div></a></li> + <li class="clearfix"><a{{ create_attribute(bundle.add_link.url.options.attributes) }} href="{{ bundle.add_link.url }}"><span class="label">{{ bundle.label }}</span><div class="description">{{ bundle.description }}</div></a></li> {% endfor %} </ul> {% elseif add_bundle_message is not empty %}