Warning: Undefined array key "#entity" in Drupal\ai_translate\Form\AiTranslateForm

Created on 17 March 2025, 23 days ago

Problem/Motivation

Having the ai_translate submodule enabled and navigating to /node/{node_id}/translations reproduces the below error.

Happens on both 1.0.x-dev and 1.1.x-dev.

Warning: Undefined array key "#entity" in Drupal\ai_translate\Form\AiTranslateForm->buildForm() (line 85 of modules/contrib/ai/modules/ai_translate/src/Form/AiTranslateForm.php).
Drupal\ai_translate\Form\AiTranslateForm->buildForm()
call_user_func_array() (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 284)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 224)
Drupal\Core\Form\FormBuilder->getForm() (Line: 50)
Drupal\ai_translate\Controller\ContentTranslationControllerOverride->overview()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

Install ai module and ai_translate submodule
Attempt to translate a node

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.1

Component

Other Submodules

Created by

🇧🇪Belgium baikho Antwerp, BE

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

Merge Requests

Comments & Activities

  • Issue created by @baikho
  • 🇧🇪Belgium baikho Antwerp, BE
  • 🇧🇪Belgium baikho Antwerp, BE
  • 🇧🇪Belgium baikho Antwerp, BE
  • 🇧🇪Belgium baikho Antwerp, BE
  • 🇧🇪Belgium baikho Antwerp, BE
  • 🇮🇹Italy bigbabert Milano, Italy

    Hi @baikho,

    have a look to Auto translation module

    BR

  • 🇬🇧United Kingdom MrDaleSmith

    I've reported that last comment as spam as this is an issue with this module, not a request for alternate modules with similar functionality.

  • Pipeline finished with Failed
    21 days ago
    Total: 205s
    #452185
  • 🇬🇧United Kingdom MrDaleSmith

    What we are seeing here is the difficult in using this module with any other translations because of the issue noted in https://www.drupal.org/project/ai/issues/3497214 📌 [AI Translate] Module uses Form that isn't a form Active - the existing code builds its own custom form so it can add in one column to the translation page, and depending on which particular controller is used that can remove a lot of important data.

    What I've done in https://git.drupalcode.org/project/ai/-/merge_requests/516 is attempt to resolve this situation by altering whatever existing page we get to add in our extra column. If anything goes wrong, it falls back to just showing what was there before ai_translate was turned on, so at the very least it won't cause major issues.

    The specific issue here was unrelated to ai_tmgmt - the problem existed with its dependency tmgmt_content so would have occurred without ai_tmgmt being installed. I'm not sure of the use case for having both ai_tmgmt and ai_translate enabled at the same time (since both send content to the AI to be translated) but if you need to, this MR should stop it causing issues.

  • Pipeline finished with Failed
    21 days ago
    Total: 286s
    #452187
  • Pipeline finished with Failed
    21 days ago
    Total: 212s
    #452235
  • Pipeline finished with Success
    21 days ago
    Total: 210s
    #452238
  • 🇬🇧United Kingdom scott_euser

    I didn't review the code, but I tested this out with TMGMT and I can use both AI Translate and TMGMT functionality on the translate tab successfully.

    Re #7 - that's a different functionality. TMGMT is for more advanced/complex translation workflows with shopping cart/review process. AI Translate should be compatible with TMGMT.

  • 🇬🇧United Kingdom lukus

    I've applied and tested the patch, but experience another error.

    Using the 1.1.x-dev version of drupal/ai.

    I'm using PHP 8.x and I get a type mismatch in Drupal\ai_translate\Controller\ContentTranslationControllerOverride as it seems one of the overridden class' properties no longer matches the property type of the class it's extending:

    protected TimeInterface $time;

    vs

    protected ?TimeInterface $time;

  • 🇬🇧United Kingdom MrDaleSmith

    That seems to be related to fixing https://git.drupalcode.org/issue/ai-3513409/-/jobs/4714593 so I'm not sure what is going on here: I may need a maintainer to look at confirm what the issue is.

  • 🇬🇧United Kingdom scott_euser

    It seems if you use Drupal 10 then its ?TimeInterface which is the problem. I pushed a fix that should solve and work in both D10 and D11. Please confirm.

Production build 0.71.5 2024