make the 'group' property on EntityReferenceSelection plugins implicitly derived

Created on 13 June 2024, 6 months ago
Updated 19 September 2024, 3 months ago

Problem/Motivation

The interplay between the plugin ID and the group property on EntityReferenceSelection plugins is weird.

Despite improving the docs for this #2945789: Document quirks of Entity reference selection plugins while a fix is figured out โ†’ , it's still confusing ๐Ÿ› Misleading documentation in \Drupal\Core\Entity\Annotation\EntityReferenceSelection Active . There is a long-standing issue to fix it ๐Ÿ› Entity reference selection plugins break when not following a weird ID pattern Needs work but no way forward.

I have an alternative suggestion: since the group property MUST conform to a certain pattern, remove it from the plugin attribute and derive it in the plugin manager.

The current rule is:

- group and id must be identical, OR
- if id is of the form foo:bar, group must be foo

Therefore, we can remove the group property from the attribute and set it in the plugin manager like this:

- if id does not contain a ':', set group to the same as the id
- if id is of the form foo:bar, set group to foo

We keep the concept of group, because it's used by EntityReferenceItem (see my comments on ๐Ÿ› Misleading documentation in \Drupal\Core\Entity\Annotation\EntityReferenceSelection Active for an explanation), but it's now impossible to get it wrong.

Steps to reproduce

Proposed resolution

Make the 'group' property on EntityReferenceSelection plugins implicitly derived

Remaining tasks

Review

User interface changes

N/A

API changes

Data model changes

N/A

Release notes snippet

๐Ÿ“Œ Task
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Entityย  โ†’

Last updated about 19 hours ago

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

๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

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

  • Issue created by @joachim
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim
  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim
  • Pipeline finished with Failed
    6 months ago
    Total: 189s
    #197982
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium kristiaanvandeneynde Antwerp, Belgium

    Can we still reach out to whoever wrote this to hear why the whole concept of groups was introduced to begin with? I feel like another solution might be to just drop the whole idea of groups.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

    In theory we could do that. The field settings would instead let you pick all the plugins that declare they work with the current entity type.

    But in the SelectionPluginManager there's a lot of logic for selecting the 'best' plugin, so of which seems irrelevant given what EntityReferenceItem does, but which could be in use in the wild. In particular, someone could have added a default:node_extra plugin and relied in the weight to get that selected automatically in a custom form that uses the entity_autocomplete element. There'd be a lot of behaviour to first DOCUMENT (!!!!) then write tests for (there are none!! SURPRISE!!!) and then deprecate with BC. I'm not against doing that, but the MR here is a nice quick solution which means no more headdesking for devs trying to write a plugin.

  • Status changed to Needs work 6 months ago
  • The Needs Review Queue Bot โ†’ tested this issue. It fails the Drupal core commit checks. 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 6 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim
  • Pipeline finished with Failed
    6 months ago
    Total: 603s
    #206862
  • Something not mentioned in the summary is that there can be more than one colon. The ID could be foo:bar:baz

  • I'm pretty sure that when it comes to selection handlers, there can be multiple colons.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

    True, but that won't make any difference. It's the base plugin ID that has to match the group.

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone
  • Status changed to Needs work 4 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Appears there are number of test failures.

  • Status changed to Needs review 4 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

    I was getting a different test failure local (?!!!) but I think this will fix both.

  • Pipeline finished with Failed
    4 months ago
    Total: 592s
    #251665
  • Pipeline finished with Failed
    4 months ago
    Total: 584s
    #251667
  • Status changed to Needs work 4 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Still appears to be failing

    Sorry took me so long to get back to this one.

  • Status changed to Needs review 4 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

    AFAICT the only failures are this deprecation:

    > Setting the 'group' property on selection plugin 'default:entity_test_with_bundle is deprecated in drupal:11.1.0 and will be removed in drupal:12.0.0. The property should be removed. See

    (Is there a way of finding test failures on gitlab? I'm having to scroll through endless pages of test result trying to look for them. Is this actually what we're meant to do?)

    But I can't reproduce locally, e.g. modules/field/tests/src/Kernel/Entity/FieldConfigValidationTest.php --filter=testEntityReferenceSelectionHandlerIsValidated runs fine for me.

    My branch is rebased, so going to push that and see what gitlab says.

  • Pipeline finished with Failed
    4 months ago
    Total: 471s
    #273650
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

    > But I can't reproduce locally, e.g. modules/field/tests/src/Kernel/Entity/FieldConfigValidationTest.php --filter=testEntityReferenceSelectionHandlerIsValidated runs fine for me.

    My phpunit.xml needed to be updated for PHPUnit 10.5.

    Fixed the test failures, I think.

  • Pipeline finished with Success
    3 months ago
    Total: 673s
    #277936
  • Status changed to Needs work 3 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Cleaned up IS some.

    Changes look good, think ready to add a CR

  • Status changed to Needs review 3 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

    Done.

  • Pipeline finished with Success
    3 months ago
    Total: 684s
    #281489
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Sahana _N

    Hi,

    I applied the patch successfully and created the custom 'EntityReferenceSelection' plugin.

    If the 'plugin_id' is "mymodule_node_type_selection:test", I did not specify any group name, so it is dynamically set to "mymodule_node_type_selection".

    If the 'plugin_id' is โ€œmymodule_node_type_selectionโ€, the group name matches the 'plugin_id'.

    So RTBC ++

    I would greatly appreciate any suggestions or if thereโ€™s anything I might have missed in testing.

    Thank you!

  • Status changed to Needs work 3 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    @sahana_n adding a screenshot of your console of a patch applying is no needed, that's evident by the MR being mergable.

    Left 2 small comments on the MR, but looks super close!

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

    > Could we get a simple test case for the deprecation test.

    Do we really have to?

    Mocking plugin discovery is really painful -- see ReflectionFactoryTest and MigrateFieldPluginManagerTest for instance. It's a LOT of test code to write just for a deprecation.

    Addressed the other points.

  • Pipeline finished with Canceled
    3 months ago
    Total: 65s
    #291276
  • Pipeline finished with Success
    3 months ago
    Total: 436s
    #291278
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Can see what other reviewers think. Thanks for the other points

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

    Been a few weeks and I could wrong about the need for a deprecation test. But will see what core committers think.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    So different case that deprecation test could be added to that ticket as an example. I'd be cool with that too.

  • The Needs Review Queue Bot โ†’ tested this issue. It fails the Drupal core commit checks. 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.

  • First commit to issue fork.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia shalini_jha

    I've checked the issue and identified an item related to the processDefinition method's return type. I've added the necessary type hint and am now moving this to Needs Review, Please review.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave
Production build 0.71.5 2024