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>&nbsp; /**<br>&nbsp;&nbsp; * Get default AI translatability for an entity type.<br>&nbsp;&nbsp; *<br>&nbsp;&nbsp; * @param string $entityTypeId<br>&nbsp;&nbsp; *&nbsp;&nbsp; Entity type ID.<br>&nbsp;&nbsp; *<br>&nbsp;&nbsp; * @return bool<br>&nbsp;&nbsp; *&nbsp;&nbsp; TRUE to translate referenced entities of this type by default.<br>&nbsp;&nbsp; */<br>&nbsp; protected function entityTypeTranslatedDefault(string $entityTypeId) : bool {<br>&nbsp;&nbsp;&nbsp; $defaults = $this-&gt;config-&gt;get('reference_defaults', []);<br><br>&nbsp;&nbsp;&nbsp; // Ensure that $defaults is an array before passing it to array_search.<br>&nbsp;&nbsp;&nbsp; if (is_array($defaults)) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (array_search($entityTypeId, $defaults) !== FALSE);<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; // Default is to not translate entities of unknown type if $defaults is not an array.<br>&nbsp;&nbsp;&nbsp; return FALSE;<br>&nbsp; }</pre>
issue