Problem/Motivation
The entity_reference_autocomplete widget generates a fatal error when autocreating a new composite entity:
Error: Call to a member function getRevisionId() on null in Drupal\entity_reference_revisions\Plugin\Field\FieldWidget\EntityReferenceRevisionsAutocompleteWidget->massageFormValues() (line 32 of modules/entity_reference_revisions/src/Plugin/Field/FieldWidget/EntityReferenceRevisionsAutocompleteWidget.php).
Proposed resolution
Fix autocreation in the entity_reference_autocomplete widget.
Remaining tasks
- Write a patch
- Review
- Commit
User interface changes
Non-existing entities referenced in the entity_reference_autocomplete widget are automatically created.
API changes
None.
Data model changes
None.
Issue fork entity_reference_revisions-2955240
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 #2
idebr commented- Added a Functional test for the autocomplete widget
- Fixed autocreation of the entity_reference_autocomplete widget
Comment #4
flyke commentedThe patch could not be applied. And if I manually apply changes from the patch in public function massageFormValues,
I get an error because
is null. So
doesn't work.
Also, if I inspect, the value of
it is the string
'previous revision'so it is not a paragraph id or something.My entire $values array does not seem to have any usable information:
Array ( [0] => Array ( [target_id] => previous revision [_weight] => 0 [_original_delta] => 0 ) [1] => Array ( [target_id] => [_weight] => 1 [_original_delta] => 1 ) )Applied patch #4 is the code from previous patch #2 for the function massageFormValues, but this one applies to latest dev version of entity_reference_revisions module, with an added
check, because that was causing errors on my project. I would urge anyone to create a better patch and test this further as my patch is missing the newly added test from #2
Comment #5
flyke commentedComment #6
benstallings commentedClaude Code says:
Minor nits
- Extra blank line before the closing } (line between the } blocks) — cosmetic, not worth blocking over.
- The patch is from 2020 — given the age, it's worth verifying it still applies cleanly to 8.x-1.x. Looking at the current file, the code at lines 37–47 matches the patch's "before" context exactly, so it should apply.
Assessment: Good fix, recommend applying. It corrects a real logic-order bug and adds a proper null guard. Both changes are defensive and correct.
I'll make a MR!
Comment #10
berdir@benstallings: Thanks for the MR, that *is* the reason this old issue is now merged, so I granted credits for that, but please do not post "Claude Code says" comments. If I'm interested in the output of an LLM, I can run it myself. See the new AGENTS.md in drupal core.