Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
I tried to render a Url object with attributes twice on inside a template. The attributes are lost after the first rendering.
Proposed resolution
Clone the Url object before rendering, the link function should have no effect on the passed url object.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#17 | interdiff.txt | 2.95 KB | dawehner |
#17 | 2842399-17.patch | 4.53 KB | dawehner |
#16 | interdiff.txt | 3.64 KB | dawehner |
#16 | 2842399-16.patch | 6.39 KB | dawehner |
#14 | 2842399-14.patch | 3.84 KB | webflo |
Comments
Comment #2
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedComment #3
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedComment #5
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedComment #6
joelpittet@webflo, I'm quite curious what removed the attributes, this solution could work but maybe better if we find where the attributes are being removed because that may have other negative effects elsewhere in the system?
Comment #8
dawehnerComment #9
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedComment #10
dawehnerThis is a unit test which renders the link twice. Its a bug in the underlying link generator.
Comment #11
dawehnerRelated bug ... #2847611: \Drupal\Core\Template\TwigExtension::getLink overrides existing classes
Comment #13
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedThe root cause is in LinkGenerator.
Comment #14
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedThis is a combination of #10 and the test-only patch from #2
Comment #16
dawehner@jorges and @dawehner debugged the remaining failure. Turns out, we need the original fix from @webflo as well.
Comment #17
dawehnerThis time with less commented out.
Comment #18
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedLooks good, nice test coverage in the LinkGenerator und TwigExtension.
Comment #19
tim.plunkettNit, s/url/URL
Fix looks good.
Comment #20
alexpottUrl should so be immutable.
Committed and pushed 9c77748 to 8.4.x and 91d653d to 8.3.x. Thanks!
Fixed on commit.