Closed (fixed)
Project:
Flag
Version:
5.x-dev
Component:
Views integration
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
23 Aug 2022 at 05:38 UTC
Updated:
3 Jan 2026 at 07:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
rudi teschner commentedAdding an additional check before rendering the links solves the problem for me, dunno if it is supposed to happen earlier though.
Comment #3
rudi teschner commentedComment #4
rudi teschner commentedForgot to consider $entity_type_id. Without it could result in a field type is unknown exception for other entity types like users.
Comment #5
ivnishComment #6
jaydev bhatt commentedi'm checking this issue.
Comment #7
jaydev bhatt commentedI was able to replicate this issue using the above description. What’s happening is that if one flag is attached to two content types and another flag is assigned to only one content type, the latter flag still generates a false link. When this link appears in the View, it renders but does not actually flag the content.
Steps to Replicate
1. Set Up Flags:
Create two flags in your Drupal site:
Flag A: Configure it to apply to content types ContentTypeA and ContentTypeB.
Flag B: Configure it to apply only to content type ContentTypeA.
2. Create Content Types:
Ensure you have at least two content types:
ContentTypeA
ContentTypeB
3. Create Content:
Create at least one node of each content type:
Node 1: Content type ContentTypeA.
Node 2: Content type ContentTypeB.
4. Add Flag Links to a View:
Create a View that displays nodes of both content types (ContentTypeA and ContentTypeB).
Add fields for both Flag A and Flag B links to the View.
5. Render the View:
Render the View and observe the flag links:
For Node 1 (ContentTypeA):
Both Flag A and Flag B links should appear and work correctly.
For Node 2 (ContentTypeB):
Only Flag A should appear and work. Flag B should not appear or should be disabled.
6. Identify the Issue:
If the Flag B link appears for Node 2 (ContentTypeB) (even though it should not), this is the issue you’re trying to replicate.
the patch above work but update attaching my version for the patch ...
here is the explanation for the changes in the patch ::
The code has been updated to improve its functionality and maintainability. Instead of using
$entity->get('type')->getString(), we now use$entity->bundle()to make the code work for any entity type, not just nodes. Early returns have been added for invalid cases, such as missing entities or flags, to make the logic clearer. The return type has been standardized to an empty array ([]) for consistency with Drupal's rendering system. Additionally, the $view_mode parameter has been included in thegetAsFlagLink()call to ensure the flag link respects the view mode. These changes make the code more generic, reusable, and aligned with Drupal best practices.with the patch that i'm attaching it will generate the flag link as per the content type if the flag is not attached to any content type it will not generate the link itself.
Also attaching the before and after screenshots for the issue for the reference
Moving this to needs Review
for the further verification of the attached patch.
Comment #8
sdhruvi5142 commentedHi, Applied "3305405_1.patch" successfully and it is working as expected.
Testing Steps:
Thanks @jaydev bhatt for giving such detailed steps. I've followed all the above mentioned steps and observed the changes there.
Testing Result:
After applying the patch, Links aren't rendering when content is not allowed for flag. Attached screenshot for reference. Moving this to RTBC+1
Status - PASS
Comment #9
ivnishNeeds reroll patch to MR
Comment #10
lavanyatalwar commentedWorking on it
Comment #12
lavanyatalwar commentedHi @ivnish, Created the MR.
Kindly review :)
Comment #13
lavanyatalwar commentedComment #14
ivnish@lavanyatalwar thanks!
MR has 2 problems:
1) phpcs issues
2) tests failed
Comment #15
jaydev bhatt commentedWorking on it.
Comment #16
jaydev bhatt commentedFix the issues with the PHPUNIT test failing.
The issue here was by default the if there is nothing selected in the flag while creating the content(node) flag it applies to all the content type present in the system. and hence the user follower flag was also not working for the same reason fixed the LinkGeneration code to apply to all the content type if the no content type is selected and fixed the PHPCS issues as well for this.
The MR is ready to merge.
Moving this to RTBC.
Comment #17
ivnishWe need a tests to demonstrate that link doesn't render in not allowed entities
Comment #18
rudi teschner commentedShort info: Patch 3305405_1.patch from #7 might not work if patch from issue 3139250 is also applied because both change the same function
Comment #19
ivnishComment #21
deaom commentedAdded test, ready for review.
Comment #22
ivnishComment #23
anaconda777 commentedthis patch #7 wont apply to latest dev or 5.0.3. (was able to patch the 4.0 beta)
Comment #24
deaom commentedThat patch in #7 is probably out dated. Create a patch from MR as MR has the latest changes. At the end of the MR link add .patch so you get Patch from MR and that creates a patch from MR.
Comment #26
ivnish