Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Hi y'all,
I created a user flag called "follow" and chose to have the link displayed on the user profile page. On the user profile pages however, the link appears twice. You can find a screenshot in the attachment.
Best,
semei
Comment | File | Size | Author |
---|---|---|---|
#12 | 1792584-2.flag_.user-profile-two-links_12.patch | 3.57 KB | scor |
#11 | 1792584-2.flag_.user-profile-two-links.patch | 3.93 KB | joachim |
#7 | 1792584.flag_.user-profile-two-links.patch | 3.61 KB | joachim |
flag.jpg | 28.12 KB | semei |
Comments
Comment #1
joachim CreditAttribution: joachim commentedConfirming this.
As a workaround, if you disable 'Display link on user profile page' you'll only get one.
Then problem is, I think, that we have two things happening at once:
- hook_entity_view() tries to show the link on the entity
- the 'Display link on user profile page' option is providing one too
Comment #2
joachim CreditAttribution: joachim commentedMore digging: the two things that show the link are:
- hook_entity_view(), tries to do this by checking $flag->uses_hook_link()
- flag_user_view, tries to do this by checking $flag->uses_hook_link()
And while in flag_entity, uses_hook_link() just checks $this->show_on_entity, in flag_user it checks $this->show_on_profile.
So clearly, the expectation is that user entities do their own work to show the link. But that probably dates back to D6, and now users can have this done for them.
Thus we could drop the special handling. But on the other hand, user profiles have a fairly specific formatting that we provide. So I think we should keep that.
My hunch is that we should drop the uses_hook_link() check from flag_user_view and check directly with the 'show_on_profile' property. Having the same access method check different properties under the hood seems a bit iffy to me anyway.
Comment #3
joachim CreditAttribution: joachim commentedHmm though this pattern is really the way uses_hook_link() seems to be meant to work: it wraps up the various type-specific properties.
Comment #4
joachim CreditAttribution: joachim commentedWe have several possible ways to fix this:
- keep the current special output on users, with the current UI options, and make hook_entity_view() aware that it has to skip the 'user' entity type. This would presumably mean an extra setting somewhere in the flag class.
- keep both ways of adding a flag to user entities. Have flag_user keep the 'show_on_entity' UI option (rather than removing it as it currently does). User flags then have both 'show_on_entity' AND 'show_on_profile'. Which is potentially confusing UI, but that can be mitigated with an explanation that 'show_on_profile' means 'format it nicely'.
I'm inclined to go got the second fix.
Comment #5
martichka5 CreditAttribution: martichka5 commentedHi,
I have the same problem. In the user profile page there are two links provided by the flag module from the flag i created.
Is there a solution for the issue?
Comment #6
joachim CreditAttribution: joachim commentedSee my earlier comment above for a couple of potential approaches. Someone who wants this fix needs to actually do the work :)
Comment #7
joachim CreditAttribution: joachim commentedComment #8
joachim CreditAttribution: joachim commentedTagging.
Comment #9
joachim CreditAttribution: joachim commentedThis allows two instances of the same flag on the user profile, hence we should also commit #843308: Support multiple instances of the same flag on single node view pages.
Comment #10
joachim CreditAttribution: joachim commentedNobody testing this? :(
Oh well -- committing, as tests pass, it works fine for me and I don't want this to rot or hold up other issues.
Issue #1792584 by joachim: Fixed flag links displayed twice on user profile.
Comment #11
joachim CreditAttribution: joachim commentedPatch will need a bit of work to backport to 2.x, if anyone's interested.
Here's the slightly updated version of what I committed -- just has an extra comment.
Comment #12
scor CreditAttribution: scor commentedbackported patch against 7.x-2.x
Comment #13
alexweber CreditAttribution: alexweber commentedRemoving 3.x release blocker tag since it's been committed and now the issue is for 2.x
Comment #14
joachim CreditAttribution: joachim commentedCommitted. Thanks!