It turns out that when you render Seven's entity-add-list.html.twig template, you cannot set additional attributes on the bundle names, because Seven does this in the template:

    {% 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>
    {% endfor %}

The problem is Seven unpacking the bundle.add_link variable, which *should* be unnecessary because it implements RenderableInterface. But anyhoo, because it unpacks the variable, any attributes set on the link's URL object are thrown right out the window. We need something like this:

    {% for bundle in bundles %}
      <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 %}

Special thanks to Wim Leers for heroically tracing this and suggesting the fix.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

phenaproxima created an issue. See original summary.

phenaproxima’s picture

Status: Active » Needs review
FileSize
865 bytes

Here's the patch.

Wim Leers’s picture

Title: Seven's entity-add-list template doesn't support link attributes » Seven's entity-add-list template omits link attributes
Issue tags: +blocker, +D8Media
Related issues: +#2831274: Bring Media entity module to core as Media module

I think this is ready, but I'm the one who suggested that exact fix, so I shouldn't be the one to RTBC this.

This is blocking #2831274: Bring Media entity module to core as Media module.

RainbowArray’s picture

Status: Needs review » Reviewed & tested by the community

Looks solid to me. I've been a bit absent from the queues, so create_attribute is new to me. I looked at the documentation, though, and this makes sense. Essentially passing the options.attributes from the add_link and manually placing them on the a element. Seems reasonable.

Fabianx’s picture

RTBC + 1

phenaproxima’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs themer review

I have a sense that we are missing something here. Should we be putting bundle.add_link.url.options.attributes in the template, or just bundle.add_link.options.attributes, which is what the code in \Drupal\Core\Render\Element\Link::preRenderLink() would seem to indicate?

I think an experienced themer needs to look at this before we can go to RTBC. Sorry, guys...

seanB’s picture

Status: Needs review » Reviewed & tested by the community

The template receives the link object directly and unpacks it so \Drupal\Core\Render\Element\Link::preRenderLink() is not used in this case.
For now I think it's RTBC.

When checking this, I saw the node add list and block content add list pages look the same but are built and rendered differently. It's currently not possible to add options for those links (the preprocessors are not providing options). It would be nice to make the developer/themer experience for this similar, but that's probably best discussed in a follow up.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

At the very least this needs tests but also the divergence between node-add-list and this and also this and the other themes is a concern.

phenaproxima’s picture

I can try to come up with tests, but regarding the divergence of this and node-add-list...well, I can't speak to why that happened, but my suspicion (based on no real evidence) is that the whole idea of a generic bundle list was in Node first, then cross-ported into the core entity system, and subsequently never removed from Node. I think they should be merged, but that would be a separate issue.

phenaproxima’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
4.92 KB
4.07 KB

Behold, a test. It's an awful lot of jury-rigging for a one-line fix, but hey...you gotta do what you gotta do.

I'm sorry about the use of the Standard profile; I couldn't figure out how to install Seven and get it to be the default admin-side theme with the Testing profile. If anyone can point me in the proper direction there, I'd appreciate it. Until then, this should do.

The last submitted patch, 10: 2836381-10.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 10: 2836381-10-FAIL.patch, failed testing.

phenaproxima’s picture

Status: Needs work » Needs review
FileSize
4.18 KB
5.02 KB

Drupal CI is such an unforgiving mistress. Forget one little @group annotation and suddenly you're a damn pariah with a bad patch.

The last submitted patch, 13: 2836381-13-FAIL.patch, failed testing.

seanB’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good. Even a FAIL patch to prove it. Nice work!

The last submitted patch, 2: 2836381-2.patch, failed testing.

The last submitted patch, 2: 2836381-2.patch, failed testing.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed f01ac2d to 8.3.x and f5c7961 to 8.2.x. Thanks!

I've committed this to 8.2.x because seven is internal and the default entity-add-list.html.twig all just print bundle.add_link so will have the attributes.

  • alexpott committed f01ac2d on 8.3.x
    Issue #2836381 by phenaproxima, Wim Leers: Seven's entity-add-list...

  • alexpott committed f5c7961 on 8.2.x
    Issue #2836381 by phenaproxima, Wim Leers: Seven's entity-add-list...
Berdir’s picture

Hm, I had a test fail on this in https://www.drupal.org/pift-ci-job/557210. Not reproducible.

drugan’s picture

Confirm the test fail related to this commit:

https://www.drupal.org/pift-ci-job/557855

Can't figure out where changes on removing test site directory might intersect with displaying link on a particular theme.

  • alexpott committed 91c4c92 on 8.3.x
    Revert "Issue #2836381 by phenaproxima, Wim Leers: Seven's entity-add-...
alexpott’s picture

Status: Fixed » Needs work

  • alexpott committed 54cec24 on 8.2.x
    Revert "Issue #2836381 by phenaproxima, Wim Leers: Seven's entity-add-...

  • alexpott committed 91c4c92 on 8.4.x
    Revert "Issue #2836381 by phenaproxima, Wim Leers: Seven's entity-add-...
  • alexpott committed f01ac2d on 8.4.x
    Issue #2836381 by phenaproxima, Wim Leers: Seven's entity-add-list...

  • alexpott committed 91c4c92 on 8.4.x
    Revert "Issue #2836381 by phenaproxima, Wim Leers: Seven's entity-add-...
  • alexpott committed f01ac2d on 8.4.x
    Issue #2836381 by phenaproxima, Wim Leers: Seven's entity-add-list...

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

chr.fritsch’s picture

I ran this test 150 times on my local machine and got zero test fails. Anyone an idea what to do here?

andypost’s picture

Looks something in core omits to initialize attributes for url somehow

Wim Leers’s picture

Status: Needs work » Needs review
FileSize
4.18 KB
5.02 KB

I can't imagine this is causing a random fail. I wonder if the random fail was merely being exhibited through this change, but the root cause was elsewhere?

#29 makes me believe that even more.

#13 still applies cleanly. Reuploading.

The last submitted patch, 31: 2836381-13-FAIL.patch, failed testing. View results

phenaproxima’s picture

Issue tags: -D8Media +Media Initiative

Re-tagging.

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs themer review

Honestly, I don't see how this could possibly have introduced a random failure either. I mean...maybe an errant functional JavaScript test that's not waiting for something it needs? But if that's the case, I have a hard time imagining that this little change to Seven would have broken that.

I would mark this for subsystem maintainer review, but...Seven has no listed maintainers in MAINTAINERS.txt. So I'm just going to kick it back to RTBC.

xjm’s picture

Status: Reviewed & tested by the community » Needs work

There was definitely a random fail introduced by this issue in December. Being dismissive and claiming there was no random fail introduced by the patch is not helpful, because there was, and it started failing immediately after commit: https://www.drupal.org/pift-ci-job/557210. Whether or not the underlying cause was elsewhere, we can't have a test that randomly fails in core, because that's introducing a critical regression.

In order to commit it, we need to prove the random fail is no longer present, and in order to do that, we would need to locate the cause. Research into the fail needs to be documented on the issue.

Thanks everyone!

xjm’s picture

See #21, #22, #24, and #30.

Thanks @chr.fritsch for running the test locally. That's a good first step. I recommend also running it more times locally, like 1000. (150 runs only has a ~3 in 4 chance of surfacing a 1% fail.) This can be done on the commit hash for the original commit.

The next step is to see if it's something that fails on the bot but not locally, which is often the case. We can create a test-only patch that runs only this test several hundred times, in a test issue, adn then trigger multiple runs of that to get a baseline for the fail rate now.

To get a baseline fail rate on the bot for when this was committed, we could maybe use 8.2.x to test it (since it's unfeasible to post a patch that reverts the entirety of 7 months of code) or even 8.1.x, but let's start with those other steps.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

vijaycs85’s picture

Status: Needs work » Needs review

Patch in #31 still applies cleanly on 8.5.x and tests are green locally:

php core/scripts/run-tests.sh --verbose  --url http://d8/ --class "Drupal\Tests\system\Functional\SevenBundleAddPageLinkAttributesTest"

Drupal test run
---------------

Tests to be run:
  - Drupal\Tests\system\Functional\SevenBundleAddPageLinkAttributesTest

Test run started:
  Sunday, October 1, 2017 - 04:36

Test summary
------------

Drupal\Tests\system\Functional\SevenBundleAddPageLinkAttribu   1 passes

Test run duration: 51 sec

Detailed test results
---------------------


---- Drupal\Tests\system\Functional\SevenBundleAddPageLinkAttributesTest ----


Status    Group      Filename          Line Function
--------------------------------------------------------------------------------
Pass      Other      SevenBundleAddPag   28 Drupal\Tests\system\Functional\Seve

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Marcin Maruszewski’s picture

FileSize
5.03 KB

I noticed that on default add bundle pages, where there are no extra attributes (the Url object options attribut is empty array, so options.attributes parameter is a NULL) there is an error like this

TypeError: Argument 1 passed to Drupal\Core\Template\TwigExtension::createAttribute() must be of the type array, null given

It means, that we cannot pass NULL to the createAttribute() method. It should be an array, even empty. I suggest add simple `Null coalescing operator` so we will pass in create_attrbute function eather initialized options attributes array from Url object options, or an empty array if the mentioned value is a NULL.

Status: Needs review » Needs work

The last submitted patch, 44: 2836381-44.patch, failed testing. View results

raman.b’s picture

Status: Needs work » Needs review
FileSize
5.06 KB
526 bytes
tanubansal’s picture

Tested #46 on 9.1
RTBC + 1

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

longwave’s picture

Project: Drupal core » Seven
Version: 9.5.x-dev » 1.0.0-alpha1
Component: Seven theme » Code

The Seven theme has been removed from Drupal 10 core. I confirmed that this issue only affects Seven and no other themes included with Drupal core, so I am moving this to the contributed Seven project.