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
Right now, the array returned from toRenderArray() is just the URL parts of a render array.
It is *always* added to '#type' => 'link' and a #title in HEAD, no exceptions.
Proposed resolution
Despite the current restricted use, a Url is not a link.
Make the method name more accurate by calling it: renderArrayProperties()
Remaining tasks
User interface changes
API changes
method rename
Comment | File | Size | Author |
---|---|---|---|
#48 | rename-2235495-48.patch | 8.24 KB | cilefen |
#45 | 2235495-toRenderArray-45.patch | 8.24 KB | tim.plunkett |
#42 | 2235495-41.patch | 8.25 KB | cilefen |
#42 | interdiff-36-41.txt | 9.5 KB | cilefen |
#36 | 2235495-36.patch | 8.92 KB | pwolanin |
Comments
Comment #1
tim.plunkettComment #2
tim.plunkettComment #3
pwolanin CreditAttribution: pwolanin commentedLooks good, though I'd make the $title param optional
$title = ''
perhaps? If it's missing maybe put in the link or generate the URL?Comment #5
tim.plunkettWe don't have any usages for that, and I don't see why they couldn't just pass in '' themselves. Generating the URL is not a bad idea either, but honestly either of those could be added later without an API change.
Comment #6
amateescu CreditAttribution: amateescu commentedHow about introducing a Link value object instead of muddying the waters in the Url class? That would be similar to the distinction we had previously with
l()
andurl()
(which made a lot of sense, imo).Comment #7
pwolanin CreditAttribution: pwolanin commented@amateescu - this came out of my concern that the current function doesn't currently return a valid render array, and the link element is the only thing that makes sense in terms of the context where it's used.
Comment #8
tim.plunkett#6, I'm not against that, but it'd be helpful to see a PoC, because as I envision it, it'd be rather ugly.
If we choose to not do either what I have in the patch or what #6 says, we can just s/toRenderArray/toRenderArrayFragment/ and be done with it.
Comment #9
amateescu CreditAttribution: amateescu commentedI think renaming the method to
toRenderArrayFragment()
would be the non-controversial change at this point. This method could be used (potentially) for the autocompete form element, something like:That's why I'd prefer to not limit its functionality to a link element.
Comment #10
tim.plunkettAgreed that it's non-controversial and make sense. I like the look of the code in #5, but I agree its a weird coupling of links and URLs.
Comment #11
andriyun CreditAttribution: andriyun commentedComment #12
denismosolov CreditAttribution: denismosolov commentedHello, folks!
I've just renamed the method. I hope I understood the task correct.
Thanks
Comment #13
andriyun CreditAttribution: andriyun commentedComment #14
tvn CreditAttribution: tvn commentedComment #15
pwolanin CreditAttribution: pwolanin commentedHow about just toRenderfragment()?
Comment #16
cilefen CreditAttribution: cilefen commentedComment #17
hottaco CreditAttribution: hottaco commentedComment #18
hotpizzas CreditAttribution: hotpizzas commentedRerolled patch.
Encountered simple conflicts in the following files:
core/modules/user/src/Form/UserCancelForm.php
core/modules/node/src/Form/NodeDeleteForm.php
core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php
core/lib/Drupal/Core/Form/ConfirmFormHelper.php
No longer exists in head:
core/modules/comment/lib/Drupal/comment/Form/DeleteForm.php
Comment #19
mrjmd CreditAttribution: mrjmd commentedComment #21
tim.plunkettThanks for rerolling!
That's not really in scope, is it?
And if so, let's make it
$title = ''
in the method signature.Whoops!
What's the reason for this change?
Comment #22
cilefen CreditAttribution: cilefen commented@tim.plunkett I addressed your comments. It looks like we really need title='' in the signature because there are some existing usages that don't include $title. Also I tried to return ConfirmFormHelper to the original intent in #5.
Comment #23
tim.plunkettMy question was why we're introducing #title in an issue that is only about renaming the toRenderArray method.
Comment #25
cilefen CreditAttribution: cilefen commentedComment #27
cilefen CreditAttribution: cilefen commentedComment #29
cilefen CreditAttribution: cilefen commentedWow, core moves fast!
Comment #31
tim.plunkettOkay, let's just get this in. It will be useful for the conversions we need to do.
Comment #32
webchickI'm showing it to eff and neither of us understand why, now that this *is* returning a full render array with a #type => link, it makes sense to rename the thing to RenderArrayFragment. Seems like this is now returning a complete render array, no?
In addition, the word "Fragment" is overloaded. Not only because of HTML Page fragments, but also because of URL fragments, and this is on the Url class. :)
If we get a re-roll of this without the rename, this should be safe for anytime post-beta. But setting to needs review first because I don't quite parse peter's concerns in #7.
Comment #33
webchickIf, on the other hand, we decide to not have the Url class making assumptions about #type being link, then effulgentsia suggests maybe toRenderArrayProperties().
Comment #34
pwolanin CreditAttribution: pwolanin commentedI'm fine with it being #type => link, but in that case I agree that we shouldn't change the method name. The whole motivation was since it didn't include a #type
Comment #35
pwolanin CreditAttribution: pwolanin commentedComment #36
pwolanin CreditAttribution: pwolanin commentedchange the method name back.
Comment #37
cilefen CreditAttribution: cilefen commentedThis satisfies the requirements of #32 and #34 and it is green.
Comment #38
dawehnerI don't think this is a sane idea, if you want to add it, just use += later or earlier. We are basically treating easy to use vs. sanity. Why should a url care about titles. If you want that, move this code to the link class
Same thing as before, a URL is not a link
Comment #39
amateescu CreditAttribution: amateescu commentedRe: #38: Yup. Also #6, #9 and #10 above.
Comment #40
pwolanin CreditAttribution: pwolanin commentedIn the face of a lack of consensus - I sought a final decision from alexpott. This is the decision:
The method should be renamed to
renderArrayProperties()
It will otherwise stay functionally the same and not provide a #type or #title.
Comment #41
pwolanin CreditAttribution: pwolanin commentedComment #42
cilefen CreditAttribution: cilefen commentedLet's see how well phpstorm handles this.
Comment #43
pwolanin CreditAttribution: pwolanin commentedsimple method name fix - looks good
Comment #45
tim.plunkettRerolled.
Comment #47
tim.plunkettInterestingly enough, #2347465: Convert all instances of #type link/links to convert to use routes removes all but 3 usages of toRenderArray (since
'#url' => $this
is used in its place)Comment #48
cilefen CreditAttribution: cilefen commentedRerolled.
Comment #49
pwolanin CreditAttribution: pwolanin commented@tim.plunkett - should we remove the method after that goes in instead?
Comment #50
dawehnerI really kinda feel that this issue is pointless.
Comment #53
dawehnerLet's do that in 9, its not worth to do that at all anymore in D8.
Comment #54
kgoel CreditAttribution: kgoel commentedComment #55
catchWe could do it in a late minor release of 8.1.x with a deprecation, if we're really going to make the full change in 9.x.
Comment #61
dawehner