From f01ac2d4d845f4819a82f775db469ec99f5d7ebf Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Wed, 21 Dec 2016 09:37:57 +0000
Subject: [PATCH] Issue #2836381 by phenaproxima, Wim Leers: Seven's
 entity-add-list template omits link attributes

---
 .../Controller/EntityTestEntityController.php | 30 ++++++++++++
 .../src/Entity/EntityTestWithBundle.php       |  2 +-
 .../src/Routing/HtmlRouteProvider.php         | 23 ++++++++++
 .../SevenBundleAddPageLinkAttributesTest.php  | 46 +++++++++++++++++++
 .../seven/templates/entity-add-list.html.twig |  2 +-
 5 files changed, 101 insertions(+), 2 deletions(-)
 create mode 100644 core/modules/system/tests/modules/entity_test/src/Controller/EntityTestEntityController.php
 create mode 100644 core/modules/system/tests/modules/entity_test/src/Routing/HtmlRouteProvider.php
 create mode 100644 core/modules/system/tests/src/Functional/SevenBundleAddPageLinkAttributesTest.php

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 000000000000..823cea958270
--- /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 c668bd3ee80b..57a7a730808d 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 000000000000..475cd34d286b
--- /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 000000000000..3a200a929cca
--- /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 3ff2e717df64..f00ecd1fc2fb 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 %}
-- 
GitLab