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.
You shouldn't have to do this before rendering a link:
$action = 'flag';
if ($flag->isFlagged($entity)) {
$action = 'unflag';
}
The renderLink() method should figure this out for itself. There is no situation where you'd want to to choose whether you want a flag or unflag link based on any other criterion -- because the link wouldn't work.
Comment | File | Size | Author |
---|---|---|---|
#8 | 2568135-8.flag_.get-link-action.patch | 4.81 KB | joachim |
#5 | 2568135-5.flag_.get-link-action.patch | 4.81 KB | joachim |
#2 | renderLink-2568135-2.patch | 5.23 KB | martin107 |
Comments
Comment #2
martin107 CreditAttribution: martin107 commentedHere is the initial version
A natural consequence of this is that we can also remove the $action parameter from
AJAXLinkController::generateResponse()
Comment #3
joachim CreditAttribution: joachim commentedThis will probably need a reroll due to #2568129: Move lazy builder callback into a service..
Also, I figured #2488856: add a wrapper around buildLink() that checks access should probably get done first. I maybe linked these two issues the wrong way round...
And I have also been wondering whether we should retain the method that doesn't check anything -- just in case there are use cases I've not envisaged. So we'd have:
getLink(): main API: does all the things for you: checks access, figures out $action. Wraps around:
renderLink(), which lets you hang yourself if you really want to.
Possible use case: you want a token in an email that you're sending out, and you want it to be a specific action, which might not be the right one at the time you're sending the email.
Comment #4
joachim CreditAttribution: joachim commentedHmm also renderLink() is probably not the right name -- if it returns a render array, it's a builder, not a renderer.
Comment #5
joachim CreditAttribution: joachim commentedComment #8
joachim CreditAttribution: joachim commentedWhoops.
Comment #10
martin107 CreditAttribution: martin107 commentedHere is what I checked.
a) The idea behind the issue is sound.
b) The change has been made in all the appropriate places.
c) I cant see any negative consequences... down the line.
I have supplied patches here so this is just a +1 form me.
Comment #11
joachim CreditAttribution: joachim commentedI think that's good enough! Thanks!
Committed.
Comment #13
martin107 CreditAttribution: martin107 commentedsorry fixed a typo in #10
I CAN NOT see any negative consequences...