Problem/Motivation
When using the entity reference selection with a configuration entity type, i.e. Views, it will return disabled configuration entities.
Steps to reproduce
- Disable a View on the site
- Create a new Entity Reference field on a content type, set it to reference Views
- Try to create content and see in the field options, your disabled view is visible
Proposed resolution
Because there is no entity query alter for configuration entities, DefaultSelection adds a status condition for configuration entity types with a status key. A new include_disabled_config handler setting controls it: FALSE leaves disabled entities out, TRUE includes them, and NULL (the default, and what fields saved before this change have) keeps the current behavior. The field settings form shows an "Include disabled entities" checkbox for these entity types.
Remaining tasks
Tests- Decide whether the default should be
FALSEinstead ofNULL, and whether that needs an update path. - Decide how existing references to an entity that is later disabled should be validated.
Change record for the newinclude_disabled_configsetting.- Review
User interface changes
- Entity reference fields to config entities with a status (such as views or text formats) no longer offer disabled entities once their field settings are saved without "Include disabled entities" checked.
- Adds an "Include disabled entities" checkbox to the field's reference settings for those entity types.
API changes
- New
include_disabled_configsetting (boolean, nullable) for thedefaultentity reference selection handler.
Data model changes
None
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3367492
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
dave reidComment #4
smustgrave commented+1 to the feature.
Seems to have caused a number of failures though.
Comment #5
dave reidI am starting to feel strongly that this should be the default behavior going forward and the default should be FALSE instead of NULL. I'm not sure what's best to get accepted though.
Comment #6
dave reidSigh, I just had an error in the config schema.
Comment #8
dave reidI rebased the MR onto
mainand added test coverage.Query.phpcleanup (str_starts_with()andstr_ends_with()) and the phpstan baseline change are gone:mainalready has both.DefaultSelectionConfigEntityStatusTest, usingconfig_test(which has a status key) andconfig_query_test(which doesn't).The test covers:
getReferenceableEntities(),countReferenceableEntities()andvalidateReferenceableEntities()leave out disabled entities wheninclude_disabled_configisFALSE, and return them when it'sTRUE.The new assertions fail without the change to
DefaultSelectionand the schema.The default stays
NULL, so existing fields and code that builds a handler without the setting (such asentity_autocompleteelements) keep returning disabled entities, and no update path is needed. A field gets the new behavior once its settings form is saved, because the unchecked checkbox savesFALSE.When a referenced config entity is disabled, content that already references it fails validation on its next save ("This entity cannot be referenced."), since
ValidReferenceConstraintValidatoronly skips existing references the user can't view. I think that's right: a field set to leave out disabled entities shouldn't keep pointing at one.Generated with the help of an LLM.
DRAFT, rewrite in your own words: I used Claude Code (Claude Opus 5.5) to rebase the MR onto
main, write the new kernel test, and draft this comment. I wrote the original fix and chose its approach. I reviewed the test and checked that it fails without the fix.Comment #9
dave reidComment #10
dave reidComment #11
needs-review-queue-bot commentedThe 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.
Comment #12
dave reidComment #13
smustgrave commentedThink for the new key we will need an upgrade hook, ConfigEntityUpdater should be able to cover it I assume.
Comment #14
smustgrave commentedFor the CR can we include a snippet in before for field.field.*.yml
Comment #15
dave reidWe can add support for the field types we know about, but entity selection plugins can be used by anything (and are also independently used by contrib modules), so I think the only way to reliably do it would we'd have to navigate every config schema, into every possible tree value, seeking for the entity selection config key. That's why I just left it as nullable and making the behavior work out of the box without it having to be updated. It would be weird to update some configs but not all configs, I would advocate for *not* having an update hook in this case for this reason but I'm willing to write it with the understanding it would only be for entity reference type fields.
Comment #16
smustgrave commentedLet’s try and get feedback from the submaintainers