- ๐ฎ๐ณIndia jaydev bhatt Pune, Maharashtra
i was able to replicate this issue using the above description what is happening is let's say if one flag is attached to 2 content types and one is set to only 1 content type ... the flag was still showing/generating the false link and when the link was in the view is was rendering but not actually flagging 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. - ๐ฎ๐ณIndia sdhruvi5142
Hi, 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 teh 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+1Status - PASS
- Merge request !125#Issue:3305405-Links rendering problem solved. โ (Open) created by lavanyatalwar
- ๐ฎ๐ณIndia lavanyatalwar
Hi @ivnish, Created the MR.
Kindly review and merge :) - ivnish Kazakhstan
@lavanyatalwar thanks!
MR has 2 problems:
1) phpcs issues
2) tests failed - ๐ฎ๐ณIndia jaydev bhatt Pune, Maharashtra
Fix the issues with the PHPUNIT test failing the issue was by default the is 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 and fixed the PHPcs issues as well for this.
The MR is ready to merge.
Moving this to RTBC. - ivnish Kazakhstan
We need a tests to demonstrate that link doesn't render in not allowed entities