Links rendered even though content is not allowed for flag

Created on 23 August 2022, over 2 years ago
Updated 19 February 2025, about 2 months ago

I've added two flags in my system and created a view with links to flag/unflag content more easily.

Flag 1: Content Type A, B
Flag 2: Content Type A

After adding relationship so that I can add the flag links fields to the output the flag 2-link for content of type B is rendered falsely - and of course not working.

๐Ÿ› Bug report
Status

Needs work

Component

Views integration

Created by

๐Ÿ‡ฉ๐Ÿ‡ชGermany Rudi Teschner

Live updates comments and jobs are added and updated live.
  • Needs reroll

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia jaydev bhatt Pune, Maharashtra

    i'm checking this issue.

  • ๐Ÿ‡ฎ๐Ÿ‡ณ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 the getAsFlagLink() 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+1

    Status - PASS

  • ivnish Kazakhstan

    Needs reroll patch to MR

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia lavanyatalwar

    Working on it

  • ๐Ÿ‡ฎ๐Ÿ‡ณ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

  • Pipeline finished with Failed
    about 1 month ago
    Total: 3297s
    #430378
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia jaydev bhatt Pune, Maharashtra

    Working on it.

  • Pipeline finished with Success
    about 1 month ago
    Total: 220s
    #432574
  • Pipeline finished with Success
    about 1 month ago
    Total: 205s
    #432590
  • ๐Ÿ‡ฎ๐Ÿ‡ณ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

Production build 0.71.5 2024