Issue #3586485: Fix ai_prompt form element in nested forms

Description

The route cause of the issue is that form element #tree property is set to FALSE. This means that each form is responsible of setting the array_parents for the form element itself. This is already done in the most of the places where the form element ai_prompt is used. It is not possible to change it to #tree => TRUE as this will be a breaking change. Instead couple of workarounds were introduced to keep track of real path to the element that is needed to fetch the form state values properly, including the usage of machine_name element that is used for AI Prompt id.

Testing instructions

  1. Install AI CKEditor module.
  2. Install AI Content Suggestions module.
  3. Go to configure the text format here /admin/config/content/formats
  4. Choose one and add "AI Assitant" button to a toolbar.
  5. Wait for the plugin settings to appear.
  6. Choose one plugin to configure, for example Summarize.
  7. Click on "Create new prompt"
  8. Observe that the form appears with Label and Prompt Text (machine name is invisible).
  9. Start typing in Label input, observe that machine name on the right (or under Label) appears and automatically created from the label.
  10. Save the form, observe that the new prompt is in the table and is selected.
  11. Save the text format. Go back to edit the format to confirm that the settings persisted.
  12. Do the same with AI Content Suggestions settings here /admin/config/ai/suggestions ("Suggest taxonomy tags" section has ai_prompt element). It should behave the same way.

Checklist

  • I have linked the related issue in the MR title or description
  • I have performed a self-review of my own code
  • I have added or updated tests, or explained in the description why this change is not covered by tests
  • I have updated documentation for any new or changed functionality
  • I have written testing instructions and verified them locally
  • I have noted any required post-merge steps (config imports, cache rebuilds, manual changes)
  • This MR contains no breaking API or hook changes, or they are explicitly documented in the description

AI Compliance

Note

Check the one that best describes your usage, or leave all unchecked if AI was not significantly used.

  • AI Assisted Code
    Mainly written by a human; AI used for autocomplete or partial generation under full human supervision.

  • AI Generated Code
    Mainly generated by AI, reviewed and approved by a human before this MR was created.

  • Vibe Coded
    Generated by AI and only functionally reviewed before this MR was created.

Closes #3586485 (closed)

Edited by Artem Dmitriiev

Merge request reports

Loading