Allow auto create for other entities within Entity Autocomplete fields

Created on 16 December 2022, almost 2 years ago
Updated 27 July 2023, over 1 year ago

Problem/Motivation

Currently, the auto-create option ("Create referenced entities if they don't already exist") only allows for taxonomy terms. I think this should be available for other entities as it is with the entity autocomplete within core.

I've seen that Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection allows for other entity types but then WebformEntityReferenceTrait unsets the form elements (auto_create and auto_create_bundle) when it's not dealing with a taxonomy term.

Steps to reproduce

  • Add a new entity_autocomplete to any form
  • Notice the "Create referenced entities if they don't already exist" option only appears when the "Type of item to reference" is set to "Taxonomy term"

Proposed resolution

Remove the restriction. I know that simply updating the condition within WebformEntityReferenceTrait will not be the only change required but with some guidance on this I could create a patch with this change and any further changes. I've tried removing the restriction within Drupal\Core\Entity\Element\EntityAutocomplete but the $element['#autocreate'] is always NULL so the selection settings don't seem to be getting passed through correctly. If I force $autocreate to be TRUE then the entity is created.

πŸ“Œ Task
Status

Closed: won't fix

Version

6.2

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom joekers UK

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

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

Production build 0.71.5 2024