Fatal error with views with relationship and argument

Created on 7 May 2024, 8 months ago
Updated 16 September 2024, 3 months ago

Problem/Motivation

Drupal Core: 10.2.6
Metatag: 2.0.0

On https://florent-torregrosa.fr/tags, I have the following fatal error:

TypeError: Cannot assign null to property Drupal\views\Plugin\views\argument\ArgumentPluginBase::$name_table_alias of type string in Drupal\views\Plugin\views\argument\ArgumentPluginBase->summaryNameField() (line 937 of core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php).
Drupal\views\Plugin\views\argument\StringArgument->summaryQuery() (Line: 882)
Drupal\views\Plugin\views\argument\ArgumentPluginBase->defaultSummary() (Line: 766)
Drupal\views\Plugin\views\argument\ArgumentPluginBase->defaultAction() (Line: 1142)
Drupal\views\ViewExecutable->_buildArguments() (Line: 1888)
Drupal\views\ViewExecutable->buildTitle() (Line: 43)
metatag_views_get_view_tags(Object, 'page_1', Array) (Line: 87)
metatag_views_metatags_alter(Array, Array, NULL) (Line: 545)
Drupal\Core\Extension\ModuleHandler->alter('metatags', Array, Array) (Line: 497)
metatag_get_tags_from_route() (Line: 131)
metatag_page_attachments(Array) (Line: 311)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}(Object, 'metatag') (Line: 388)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('page_attachments', Object) (Line: 308)
Drupal\Core\Render\MainContent\HtmlRenderer->invokePageAttachmentHooks(Array) (Line: 285)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 284)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
Drupal\Core\Render\MainContent\HtmlRenderer->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)
require('/project/app/index.php') (Line: 4)

When uninstalling metatag_views there is no more fatal error.

The problem happens when there is no argument provided because on pages like https://florent-torregrosa.fr/tags/Drupal there is no fatal error.

I attach the view configuration. It is used to build pages like the "Archive" view but based on tags.

Steps to reproduce

- Have a view on content with a relationship on tags and a view argument on the taxonomy term name to build a summary.
- Have Metatag Views enabled.

Proposed resolution

TBD

Remaining tasks

Find the bug origin.

🐛 Bug report
Status

Active

Version

2.0

Component

Views integration

Created by

🇫🇷France Grimreaper France 🇫🇷

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

Comments & Activities

  • Issue created by @Grimreaper
  • 🇧🇴Bolivia manuvelasco Bolivia

    Drupal: 10.2.7
    Metatag: 2.0.0
    I'm having the same bug after installing metatag_views with the following error message.
    The website encountered an unexpected error. Try again later.

    Error: Attempt to assign property "type" on null in Drupal\views\ManyToOneHelper->ensureMyTable() (line 195 of core/modules/views/src/ManyToOneHelper.php).
    Drupal\views\Plugin\views\argument\StringArgument->query(1) (Line: 1126)
    Drupal\views\ViewExecutable->_buildArguments() (Line: 1888)
    Drupal\views\ViewExecutable->buildTitle() (Line: 43)
    metatag_views_get_view_tags(Object, 'page_1', Array) (Line: 87)
    metatag_views_metatags_alter(Array, Array, NULL) (Line: 545)
    Drupal\Core\Extension\ModuleHandler->alter('metatags', Array, Array) (Line: 497)
    metatag_get_tags_from_route() (Line: 131)
    metatag_page_attachments(Array) (Line: 311)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}(Object, 'metatag') (Line: 388)
    Drupal\Core\Extension\ModuleHandler->invokeAllWith('page_attachments', Object) (Line: 308)
    Drupal\Core\Render\MainContent\HtmlRenderer->invokePageAttachmentHooks(Array) (Line: 285)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 627)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 284)
    Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
    Drupal\Core\Render\MainContent\HtmlRenderer->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)

  • 🇮🇳India dev2.addweb

    The TypeError happens because the buildTitle() method, when called, expects certain properties to be properly initialized. If the view lacks the required arguments or filters, these properties may be null or not properly set, leading to the error.

    In my project I have solved this error using the following code : which presents inside metatag\metatag_views\metatag_views.module function metatag_views_get_view_tags($view, $display_id = NULL, $args = []) {

    // $view->buildTitle();
    $contextual_filters = !empty($view->args) ? $view->args : [];
    $exposed_input = !empty($view->getExposedInput()) ? $view->getExposedInput() : [];
    $query_options = !empty($view->query->options) ? $view->query->options : [];
    
    if(!empty($contextual_filters) || !empty($exposed_input) || !empty($query_options)) {
    $view->buildTitle();
    }
    
    

    These are some probable instances, however more checks are needed to avoid the issue

Production build 0.71.5 2024