Latest dev build gives haystack error

Created on 14 September 2024, 10 months ago
Updated 17 September 2024, 10 months ago

After updating to the latest dev build, attempting to translate a piece of content gave an error:
The website encountered an unexpected error. Try again later.

If I inspect the recent logs, I see the following error:
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).

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:

  /**
   * Get default AI translatability for an entity type.
   *
   * @param string $entityTypeId
   *   Entity type ID.
   *
   * @return bool
   *   TRUE to translate referenced entities of this type by default.
   */
  protected function entityTypeTranslatedDefault(string $entityTypeId) : bool {
    $defaults = $this->config->get('reference_defaults', []);

    // Ensure that $defaults is an array before passing it to array_search.
    if (is_array($defaults)) {
      return (array_search($entityTypeId, $defaults) !== FALSE);
    }

    // Default is to not translate entities of unknown type if $defaults is not an array.
    return FALSE;
  }
πŸ› Bug report
Status

Fixed

Version

1.0

Component

Other Submodules

Created by

πŸ‡ΊπŸ‡ΈUnited States w01f

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024