Add setting to EntityReferenceSelection plugins to prevent references to referencing entity

Created on 5 June 2014, about 11 years ago
Updated 7 February 2023, over 2 years ago

Problem/Motivation

There should be an option to prevent entity selection plugins from referencing the entity. Where an entity selection plugin is called because it is attached as a field to an entity

Remaining tasks

None

User interface changes

Add checkbox to field configuration

API changes

None

Config/Data model changes

Add configuration for site builders to choose whether to prevent self references.

โœจ Feature request
Status

Needs work

Version

10.1 โœจ

Component
Entityย  โ†’

Last updated 1 day ago

  • Maintained by
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom @catch
  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland @berdir
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany @hchonov
Created by

Live updates comments and jobs are added and updated live.
  • Contributed project blocker

    It denotes an issue that prevents porting of a contributed project to the stable version of Drupal due to missing APIs, regressions, and so on.

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.

  • ๐Ÿ‡ง๐Ÿ‡ทBrazil carolpettirossi Campinas - SP

    This would be really really useful. It's very common to have Content referencing other content of the same type to create blocks like "Related Articles", "Recommended products" and editors being responsible to curate these blocks by choosing the specific nodes in the entity reference field.

    I tested the patch from #79 and it did not work as I show in the video attached:
    Screenshare - 2023-02-07 12_05_04 PM.mp4 (3.96 MB)

  • Status changed to Needs review over 2 years ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia nitin shrivastava

    For, d10 #79 patch not applied cleanly.
    Fix for d10

  • Status changed to Needs work over 2 years ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request โ†’ as a guide.

    Issue summary should include the proposed solution to the problem.

    Also since we are adding a new setting this seems like it could affect existing sites. Think we would need an upgrade path.

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland berdir Switzerland

    This needs to be redone on top of ๐Ÿ› Entity autocomplete widget does not pass along entity to AJAX request Fixed . That issue already added a test implementation for this, we just need to convert that to a setting like this issue is doing. We can probably remove the test implementation there again.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada Liam Morland Ontario, CA ๐Ÿ‡จ๐Ÿ‡ฆ

    Liam Morland โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada Liam Morland Ontario, CA ๐Ÿ‡จ๐Ÿ‡ฆ

    I have created a merge request with the patch in #88 ported to 11.x.

    Upgrade path: Perhaps the variable should be prevent_self_reference instead of allow_self_reference. That way, if it is not set, it has the same behaviour as before. Nothing changes until someone configures it differently.

  • Pipeline finished with Success
    over 1 year ago
    Total: 494s
    #126246
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada Liam Morland Ontario, CA ๐Ÿ‡จ๐Ÿ‡ฆ

    The upgrade path already works. I installed this on my 10.2.4 site. In my test field, allow_self_reference was already checked and self-reference was allowed, as before. I unchecked it and self-reference was prevented.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada Liam Morland Ontario, CA ๐Ÿ‡จ๐Ÿ‡ฆ
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada Liam Morland Ontario, CA ๐Ÿ‡จ๐Ÿ‡ฆ

    Patch from merge request ported to Drupal 10.2.4.

  • Status changed to Needs work over 1 year ago
  • The Needs Review Queue Bot โ†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada Liam Morland Ontario, CA ๐Ÿ‡จ๐Ÿ‡ฆ

    The bot is referring to the patch in 97. The current version is the merge request.

  • Status changed to Needs work over 1 year ago
  • The Needs Review Queue Bot โ†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada Liam Morland Ontario, CA ๐Ÿ‡จ๐Ÿ‡ฆ

    Patch from merge request, just to stop the bot from resetting the status.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    If going to add a new UI setting will probably need usability sign off.

    Also with schema change going to an upgrade path.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada Liam Morland Ontario, CA ๐Ÿ‡จ๐Ÿ‡ฆ

    Who does the usability sign-off?

    Does this need an upgrade hook or would it be OK to write it so that if allow_self_reference is not set, is is treated as true to preserve existing behaviour?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Can post in #ux for them to take a look, they also keep an eye on the tag.

    If a configuration file is being updated it will need an upgrade path.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada Liam Morland Ontario, CA ๐Ÿ‡จ๐Ÿ‡ฆ

    I rebased the merge request on 11.x. The patch is the current state of the merge request.

  • Pipeline finished with Failed
    7 months ago
    Total: 198s
    #365815
  • Pipeline finished with Success
    7 months ago
    Total: 795s
    #365824
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada Liam Morland Ontario, CA ๐Ÿ‡จ๐Ÿ‡ฆ

    Test are now passing.

  • Pipeline finished with Failed
    2 months ago
    Total: 104s
    #496018
  • Pipeline finished with Failed
    about 2 months ago
    Total: 95s
    #509678
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada Liam Morland Ontario, CA ๐Ÿ‡จ๐Ÿ‡ฆ

    @smustgrave thanks for the feedback.

    The only non-PHP file that this issue updates is core/config/schema/core.data_types.schema.yml. Does that require an upgrade path? If so, what would the upgrade path be? I thought it would pick-up the schema change on the next cache clear.

    When you say "post in #ux", is that referring to a Slack channel? I haven't used Slack for Drupal.

  • Pipeline finished with Success
    about 2 months ago
    Total: 931s
    #509679
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    If this is a new key that will appear in config during an export then the upgrade path would be to add that key to all entity reference selection plugins.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada Liam Morland Ontario, CA ๐Ÿ‡จ๐Ÿ‡ฆ

    So, an update hook to set allow_self_reference = TRUE on all entity reference fields? Would it be OK to have it be that if allow_self_reference is NULL, it because as if it were TRUE? That would preserve existing behaviour without the need for an update hook.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Is this key going to appear in config yml file on config export

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada Liam Morland Ontario, CA ๐Ÿ‡จ๐Ÿ‡ฆ

    allow_self_reference will appear in config export.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Gotcha. So that key needs to be set in the upgrade hook. Probably needs to be a configUpdateImporter like views does it so it can be in batches.

    Probably has to be set to FALSE to maintain existing behavior

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada Liam Morland Ontario, CA ๐Ÿ‡จ๐Ÿ‡ฆ

    The current behaviour is that self-referencing is possible, which is the meaning of allow_self_reference = TRUE.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Then update hook can set to TRUE. Whichever one keeps existing behavior so peopleโ€™s sites donโ€™t randomly break

Production build 0.71.5 2024