Installation/configuration resilience (ai_translate)
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3498757. --> Reported by: [dunx](https://www.drupal.org/user/445642) Related to !406 >>> <p>I experienced this error when re-testing an ai_translate issue, so this is a new issue raised from that testing covered under <a href="https://www.drupal.org/project/ai/issues/3494285#comment-15930348">https://www.drupal.org/project/ai/issues/3494285#comment-15930348</a></p> <p>The issues may be related to ai_translate specifically, or they may be a symptom of wider issues with AI Core.</p> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>When installing and configuring AI Translate, you can encounter a number of unhelpful errors and messages if you do not undertake that correctly.</p> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <p>Using D11 Umami with just the following core and modules enabled:</p> <ul> <li>Drupal Core 11.1.1 - long list</li> <li>Admin Toolbar 3.5.1 - toolbar and extras</li> <li>AI (Artificial Intelligence) 1.0.0-beta7 - AI Core and AI Translate</li> <li>Key 8.x-1.19</li> </ul> <p>I'm logged in as the admin account. I haven't configured anything yet, which is the cause of my woes.</p> <p>I created an article and then clicked on the Translate tab.</p> <p>I see the following errors:</p> <ul> <li>Error message - Please set a default chat provider &amp; model in the AI module settings.</li> <li>Error message - Warning: Undefined array key 1 in Drupal\ai_translate\Form\AiTranslateForm-&gt;buildForm() (line 116 of modules/contrib/ai/modules/ai_translate/src/Form/AiTranslateForm.php).</li> </ul> <p>The first error is useful. I should not get the second error. The stack trace is:</p> <pre>TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /var/www/html/web/core/lib/Drupal/Component/Render/FormattableMarkup.php on line 238 in Drupal\Component\Utility\Html::escape() (line 431 of core/lib/Drupal/Component/Utility/Html.php).<br>Drupal\Component\Render\FormattableMarkup::placeholderEscape() (Line: 187)<br>Drupal\Component\Render\FormattableMarkup::placeholderFormat() (Line: 195)<br>Drupal\Core\StringTranslation\TranslatableMarkup-&gt;render() (Line: 15)<br>Drupal\Core\StringTranslation\TranslatableMarkup-&gt;__toString() (Line: 203)<br>Drupal\Core\Utility\LinkGenerator-&gt;doGenerate() (Line: 180)<br>Drupal\Core\Utility\LinkGenerator-&gt;generate() (Line: 164)<br>Drupal\Core\Link-&gt;toString() (Line: 128)<br>Drupal\ai_translate\Form\AiTranslateForm-&gt;buildForm()<br>call_user_func_array() (Line: 528)<br>Drupal\Core\Form\FormBuilder-&gt;retrieveForm() (Line: 279)<br>Drupal\Core\Form\FormBuilder-&gt;buildForm() (Line: 219)<br>Drupal\Core\Form\FormBuilder-&gt;getForm() (Line: 19)<br>Drupal\ai_translate\Controller\ContentTranslationControllerOverride-&gt;overview()<br>call_user_func_array() (Line: 123)<br>Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 593)<br>Drupal\Core\Render\Renderer-&gt;executeInRenderContext() (Line: 121)<br>Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;wrapControllerExecutionInRenderContext() (Line: 97)<br>Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 183)<br>Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw() (Line: 76)<br>Symfony\Component\HttpKernel\HttpKernel-&gt;handle() (Line: 53)<br>Drupal\Core\StackMiddleware\Session-&gt;handle() (Line: 48)<br>Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle() (Line: 28)<br>Drupal\Core\StackMiddleware\ContentLength-&gt;handle() (Line: 32)<br>Drupal\big_pipe\StackMiddleware\ContentLength-&gt;handle() (Line: 116)<br>Drupal\page_cache\StackMiddleware\PageCache-&gt;pass() (Line: 90)<br>Drupal\page_cache\StackMiddleware\PageCache-&gt;handle() (Line: 48)<br>Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle() (Line: 51)<br>Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle() (Line: 36)<br>Drupal\Core\StackMiddleware\AjaxPageState-&gt;handle() (Line: 51)<br>Drupal\Core\StackMiddleware\StackedHttpKernel-&gt;handle() (Line: 709)<br>Drupal\Core\DrupalKernel-&gt;handle() (Line: 19)</pre><p>I want to use Open AI, but visiting the link displayed by the module under "Default providers" at /en/admin/config/ai/settings to /en/admin/config/ai/providers gives me an access denied error. I am admin and shouldn't see an access denied error and the cause of the issue is not clear to me.</p> <p>Ooops... so I'd missed the ai_provider_openai module.</p> <p>I installed and enabled that module.<br> I added my Open AI key via /en/admin/config/system/keys and configured ai_provider_openai to use that key at /en/admin/config/ai/providers/openai</p> <p>That access denied error has gone away :)</p> <p>I click on the Translate tab again. Same two errors :(</p> <p>Ooops... I haven't configured AI Translate to use Open AI yet.<br> Dropdown at /en/admin/config/ai/ai-translate says to use the "Default from AI Module (chat)", which is just as well as there's no AI option under "Translate Text" at AI settings (/en/admin/config/ai/settings) which is what I was expecting to have to configure.<br> So I configure the Chat at that same URL to use Open AI and gpt-3.5-turbo.</p> <p>I click the Translate tab again. Hoorah, no errors.</p> <p>I click on "Translate using gpt-3.5-turbo" to create a Spanish translation. That works.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Make the module more resilient to misconfiguration, perhaps providing more helpful messages to guide users to a successful installation.</p> <p>--UPDATE--</p> <p>Ticket scope reduced to deal with the PHP error, not the Access Denied error that occurs afterwards, which I will raise as a separate issue.</p>
issue