Summary
Backport of MR #1 (→ 2.x) to 2.0.x for #3586515. Same change as the parent issue #3577050 (closed) / !1536 (merged), ported across the major-version boundary.
Because the FieldWidgetAction plugins and the kernel test are byte-identical between 2.x and 2.0.x, this is a clean git cherry-pick -x of the 2.x commit — no manual conflict resolution was needed on top of the 2.x work.
Cherry picked from the 2.x branch (commit
c60b0854). Please review/merge after MR #1 lands on 2.x.
What changed
The per-widget automator dispatch logic is generalized into AutomatorBaseAction:
runAutomatorSubmit()runs the automator once during the submit phase andsetFormInput()writes results into$form_stateuser input, so the rebuilt form scaffolds enough delta slots for every value returned.- Two extension points let plugins customize only what they need:
transformFormInput()— remap a field item to the widget's expected input shape (e.g.target_id→fids).setFormInput()— override for widgets that declaremultiple_values = TRUE(single element for all deltas, e.g. boolean checkbox, options_select, tags autocomplete).
updateItemsCount()bumps the widget'sitems_countbefore rebuild so extra values aren't dropped.- Single-value list widgets share a new
ListBaseparent (ListString/ListInteger/ListFloatare now thin subclasses). - Most per-widget plugins shed their bespoke
aiAutomatorsAjax()/saveFormValues()boilerplate. Plugins with non-standard form trees keep custom dispatch: Chart, ImageAltText, ImageFilename, TextToImageMediaLibrary, TextToAudioMediaLibrary, Metatag, OfficeHours, SummaryTextareaWithSummary, ClassificationOptionsSelect.
Net: 29 files, +1224 / −1614.
Automated tests
Adds FieldWidgetActionFormInputTest (kernel, 16 tests / 261 assertions) covering each input shape: default per-delta, flat multi-value, fids remap, scalar list input, sub-key (state), summary-only merge, legacy no-op plugins, and items_count bumping/non-shrinking.
# from project root (DDEV)
ddev exec bash -lc 'SIMPLETEST_DB="mysql://db:db@db/db" \
vendor/bin/phpunit -c web/core \
web/modules/contrib/ai/modules/ai_automators/tests/src/Kernel/Plugin/FieldWidgetAction/FieldWidgetActionFormInputTest.php'Manual testing
- Enable AI Automators and a provider; create an Automator for a target field.
- Edit the field's form-display widget → enable the matching Field Widget Action and select the Automator.
- On the node add/edit form, click the automator button on that field and confirm:
- Single-value widgets (text, email, telephone, list select/radios, boolean, link, number) populate the generated value into the widget.
- Multi-value fields receive one value per delta, and the widget grows to hold all returned values (no values silently dropped).
- Tags autocomplete populates comma-separated tags; options_select / chosen receive a flat list; boolean checkbox toggles correctly.
- Remap cases: image/file widgets show the previewed file (
target_id→fids); moderation state sets via the state sub-key; summary+textarea updates only the summary while preserving the body you typed. - Special layouts (Chart, alt-text on media library, text-to-image/audio media library, metatag, office hours) still populate as before.
- Confirm the AJAX rebuild leaves no console/PHP errors and the values persist on save.
Notes for reviewers
- Verified on the 2.0.x base: kernel suite 16/16 green, phpcs (Drupal, DrupalPractice) clean.
- phpstan (level 7, non-blocking in CI) reports the inherited
missingType.iterableValuenags on the new/moved methods — same category accepted in !1536 (merged); no new logic-level findings.