Error when trying to bulk operations field to a Search API view that lists translatable content

Created on 27 November 2024, 4 months ago

Problem/Motivation

Vyskytla sa chyba AJAX HTTP.
HTTP Result Code: 500
Debugging information follows.
Path: /admin/structure/views/view/produkty/preview/page_1
Stavový text: error
ResponseText: The website encountered an unexpected error. Try again later.Drupal\Component\Plugin\Exception\PluginNotFoundException: The "" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 139 of core/lib/Drupal/Core/Entity/EntityTypeManager.php). Drupal\views\Plugin\views\field\BulkForm->getEntityTranslationRenderer() (Line: 98)
Drupal\views\Plugin\views\field\BulkForm->getEntityTranslationByRelationship(Object, Object) (Line: 144)
Drupal\search_api\Plugin\views\field\SearchApiBulkForm->viewsForm(Array, Object) (Line: 111)
Drupal\views\Form\ViewsFormMainForm->buildForm(Array, Object, Object, Array) (Line: 172)
Drupal\views\Form\ViewsForm->buildForm(Array, Object, Object, Array)
call_user_func_array(Array, Array) (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm('views_form_produkty_page_1', Object) (Line: 283)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 224)
Drupal\Core\Form\FormBuilder->getForm(Object, Object, Array) (Line: 2262)
Drupal\views\Plugin\views\display\DisplayPluginBase->elementPreRender(Array)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 859)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 421)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 493)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 493)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 493)
Drupal\Core\Render\Renderer->doRender(Array, 1) (Line: 240)
Drupal\Core\Render\Renderer->render(Array, 1) (Line: 153)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 154)
Drupal\Core\Render\Renderer->renderRoot(Array) (Line: 66)
Drupal\Core\Render\MainContent\AjaxRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
"

Steps to reproduce

1. add multiple languages to the website
2. enable translation for content types
3. add search API indexing contents all languages
4. try to build a Search API based view that lists content in the current language and try to add the Bulk operations field

Proposed resolution

Remaining tasks

🐛 Bug report
Status

Active

Version

1.0

Component

Views integration

Created by

🇸🇰Slovakia kaszarobert

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

Merge Requests

Comments & Activities

  • Issue created by @kaszarobert
  • 🇸🇰Slovakia kaszarobert

    Here's a quick fix we made to continue rendering when the langcode could not be detected for some reason. Maybe there's a better way to propagate this but I didn't have the time to dive deep into it.

  • 🇦🇹Austria drunken monkey Vienna, Austria

    drunken monkey made their first commit to this issue’s fork.

  • 🇦🇹Austria drunken monkey Vienna, Austria

    Thanks for reporting this problem!
    I could indeed reproduce it right away: If there are translations in the view (maybe even just if the site is multilingual) there is a fatal error.
    Looking at the code, I actually think we don’t even need getEntityTranslationByRelationship(). In our case, the result entities should all already have the correct language.

    I created an MR with that approach, please try it out and tell me if it resolves the problem for you!

    I also tried amending SearchApiBulkFormTest to catch this problem in the future, just by adding one translation to the test entities. However, for some reason which I couldn’t figure out for the life of me the translation I added just didn’t save properly. See the attached patch – maybe you (or someone else?) are able to make it work?
    (For me, this fails at the last line tagged with # Temporary debug code. – the translation is just not there anymore after reloading the entity.)
    In any case I think we should have a regression test for this before merging.

  • 🇦🇹Austria drunken monkey Vienna, Austria

    Would be great to get a) feedback and b) help on that test. It has to be something stupid, probably because I’m unused to working with translations – maybe someone more experienced there can quickly spot my mistake?

Production build 0.71.5 2024