Latest AI dev build gives haystack error in translate code
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3474442. -->
Reported by: [w01f](https://www.drupal.org/user/2488816)
>>>
<p>After updating to the latest dev build, attempting to translate a piece of content gave an error:<br>
The website encountered an unexpected error. Try again later.</p>
<p>If I inspect the recent logs, I see the following error:<br>
TypeError: array_search(): Argument #2 ($haystack) must be of type array, null given in array_search() (line 191 of /home/customer/www/kobejet.com/web/modules/contrib/ai/modules/ai_translate/src/Plugin/FieldTextExtractor/ReferenceFieldExtractor.php).</p>
<p>Adding a null check before calling array_search() appears to prevent this error in this case, but I'm unsure if this is the proper fix. I modified the end of the ReferenceFieldExtractor.php file at /modules/contrib/ai/modules/ai_translate/src/Plugin/FieldTextExtractor/ReferenceFieldExtractor.php to:</p>
<pre> /**<br> * Get default AI translatability for an entity type.<br> *<br> * @param string $entityTypeId<br> * Entity type ID.<br> *<br> * @return bool<br> * TRUE to translate referenced entities of this type by default.<br> */<br> protected function entityTypeTranslatedDefault(string $entityTypeId) : bool {<br> $defaults = $this->config->get('reference_defaults', []);<br><br> // Ensure that $defaults is an array before passing it to array_search.<br> if (is_array($defaults)) {<br> return (array_search($entityTypeId, $defaults) !== FALSE);<br> }<br><br> // Default is to not translate entities of unknown type if $defaults is not an array.<br> return FALSE;<br> }</pre>
issue