Field Widget Action throws error when associated Automator is removed from field
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3537838. --> Reported by: [sijumpk](https://www.drupal.org/user/389053) Related to !806 !917 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>When an AI automator is removed from a field's configuration but its associated <strong>Field Widget Actions</strong> are left in place, triggering the action causes a fatal error.</p> <p><strong>UI Error Message:</strong><br> <code>Oops, something went wrong. Check your browser's developer console for more details.</code></p> <p><strong>Recent log entry:</strong><br> <code> Error: Call to a member function get() on null in Drupal\ai_automators\Plugin\FieldWidgetAction\AutomatorBaseAction-&gt;populateAutomatorValues() (line 245 of /modules/contrib/ai/modules/ai_automators/src/Plugin/FieldWidgetAction/AutomatorBaseAction.php) </code></p> <p>This occurs because the field widget action still tries to reference a removed automator.</p> <h4 id="summary-steps-reproduce">Steps to reproduce (required for bugs, but not feature requests)</h4> <ol> <li>Go to <em>Manage fields</em> for the <strong>Basic page</strong> content type.</li> <li>Add a new field of type <strong>Plain text</strong> called <strong>Label</strong>.</li> <li>In the field settings: <ul> <li>Check <strong>Enable AI Automator</strong></li> <li>Select <strong>LLM: Text</strong> for <strong>AI Automator Type</strong></li> <li>Set <strong>Automator Input Mode</strong> to <strong>Base Mode</strong></li> <li>Select <strong>Title</strong> for <strong>Automator Base Field</strong></li> <li>Set <strong>Automator Prompt</strong> to: <code>Return only the word "Hello"</code></li> </ul> </li> <li>Save the field settings.</li> <li>Go to the <strong>Manage form display</strong> tab.</li> <li>Ensure the <strong>Label</strong> field uses the <strong>Textfield</strong> widget.</li> <li>Click the gear icon for the widget settings.</li> <li>Expand the <strong>Field Widget Actions</strong> section and: <ul> <li>Add an action of type <strong>Automator Text Suggestion</strong></li> <li>Enable the <strong>Enable Automators</strong> checkbox</li> <li>Set <strong>Button label</strong> to <code>Generate</code></li> <li>Set <strong>Automator to use for suggestions</strong> to <strong>Label Default</strong></li> </ul> </li> <li>Go to <em>Add Basic page</em>, enter a title, and click <strong>Generate</strong> &rarr; it works fine.</li> <li>Return to the <strong>Label</strong> field settings and <strong>uncheck Enable AI Automator</strong> to disable the automator.</li> <li><strong>Do not</strong> remove or update the widget action.</li> <li>Return to the <em>Add Basic page</em> form and click <strong>Generate</strong> again.</li> </ol> <p><strong>Result:</strong> UI error and PHP fatal error.</p> <p><strong>Expected:</strong> Widget action should handle missing automator gracefully or not be available once automator is removed.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <ul> <li>When an automator is removed from a field, automatically remove or disable the associated <strong>Field Widget Actions</strong>.</li> <li>Alternatively, update the widget action plugin to validate the existence of the automator before attempting to access it.</li> </ul> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <ul> <li>Fix the issue so that field widget actions do not cause errors when the associated automator is removed.</li> </ul> <h3>Optional: Other details as applicable (e.g., User interface changes, API changes, Data model changes)</h3>
issue