Add a common method for suggestions in Field Widget Actions
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3534716. -->
Reported by: [marcus_johansson](https://www.drupal.org/user/385947)
Related to !763
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>Currently there is the possibility to either process and fill out a field automatically, but also process and give multiple suggestions back and pick from them.</p>
<p>The later can be viewed in the <a href="https://git.drupalcode.org/project/ai/-/blob/1.2.x/modules/ai_content_suggestions/src/Plugin/FieldWidgetAction/PromptContentSuggestion.php?ref_type=heads#L211">AI Content Suggestions</a> module where it returns a suggestion pick.</p>
<p>This will probably be a common pattern for processors to want to implement, and instead of every plugin implementing this by copy and pasting code, we should have a common method for it, that implements the JS libraries needed and returns an AjaxResponse that can be used as the response of the form.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<ul>
<li>Discuss if the following is the correct solution.</li>
<li>Create a method on the base class FieldWidgetActionBase that is called returnSuggestions.</li>
<li>It should return an AjaxResponse, that the processor can return.</li>
<li>It should take an associative array of suggested values, where the key is the value and the value is a human readable suggestions, that can take HTML in the case of images, audio or other multimodalities.</li>
<li>It should take the field name.</li>
<li>It should take the delta, if its a multivalue field.</li>
</ul>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<ul>
<li>Discuss if it should recognize patterns instead of give it HTML - image file becomes an <img href="https://www.drupal.org"> tag etc.</li>
</ul>
issue