Summary
Ports the field widget action (FWA) / Automators generalization from !1536 (merged) (issue #3577050 (closed), merged to 1.4.x) onto 2.x, as requested in #3586515. The 1.x work could not be cherry-picked directly across the major-version boundary, so this is a 3-way port of the same change set.
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 (boilerplate removed, logic centralized).
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'The existing AutoCompleteTagsTaxonomyTest (FunctionalJavascript) continues to cover the tags-autocomplete flow end to end on CI.
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 locally: 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. - A 2.0.x backport will follow in a separate MR once this lands.