PHP upgrade error: Undefined array key "id" in Drupal\views\Plugin\views\display\DisplayPluginBase->getHandlers()

Created on 19 October 2022, over 2 years ago
Updated 14 February 2023, about 2 years ago

Problem/Motivation

We recently upgrade to PHP 8.1 over our drupal site Drupal core 9.4.8, we saw this error at display catalog page

Warning: Undefined array key "id" in Drupal\views\Plugin\views\display\DisplayPluginBase->getHandlers() (line 864 of /var/www/web/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php)
#0 /var/www/web/core/includes/bootstrap.inc(347): _drupal_error_handler_real(2, 'Undefined array...', '/var/www/web/co...', 864)
#1 /var/www/web/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(864): _drupal_error_handler(2, 'Undefined array...', '/var/www/web/co...', 864)
#2 /var/www/web/core/modules/views/src/ViewExecutable.php(1043): Drupal\views\Plugin\views\display\DisplayPluginBase->getHandlers('filter')
#3 /var/www/web/core/modules/views/src/ViewExecutable.php(901): Drupal\views\ViewExecutable->_initHandler('filter', Array)
#4 /var/www/web/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(2319): Drupal\views\ViewExecutable->initHandlers()
#5 /var/www/web/core/modules/views/src/ViewExecutable.php(1695): Drupal\views\Plugin\views\display\DisplayPluginBase->preExecute()
#6 /var/www/web/core/modules/views/src/ViewExecutable.php(1630): Drupal\views\ViewExecutable->preExecute(Array)
#7 /var/www/web/core/modules/views/src/Element/View.php(81): Drupal\views\ViewExecutable->executeDisplay('page_1', Array)
#8 [internal function]: Drupal\views\Element\View::preRenderViewElement(Array)
#9 /var/www/web/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(101): call_user_func_array(Array, Array)
#10 /var/www/web/core/lib/Drupal/Core/Render/Renderer.php(772): Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_ren...', 'exception', 'Drupal\\Core\\Ren...')
#11 /var/www/web/core/lib/Drupal/Core/Render/Renderer.php(363): Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array)
#12 /var/www/web/core/lib/Drupal/Core/Render/Renderer.php(201): Drupal\Core\Render\Renderer->doRender(Array, false)
#13 /var/www/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(241): Drupal\Core\Render\Renderer->render(Array, false)
#14 /var/www/web/core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#15 /var/www/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(242): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#16 /var/www/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(132): Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))
#17 /var/www/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))
#18 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#19 /var/www/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#20 /var/www/vendor/symfony/http-kernel/HttpKernel.php(164): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view')
#21 /var/www/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#22 /var/www/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /var/www/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /var/www/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /var/www/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 /var/www/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 /var/www/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 /var/www/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 /var/www/web/core/lib/Drupal/Core/DrupalKernel.php(709): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 /var/www/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#31 {main}

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

No change, just the PHP upgrade from 7.4 to 8.1.8, and a couple of module upgrade.

API changes

No change, just the PHP upgrade from 7.4 to 8.1.8, and a couple of module upgrade.

Data model changes

no change

Release notes snippet

Please advice which patching can fix this problem, thank you

πŸ› Bug report
Status

Postponed: needs info

Version

9.5

Component
ViewsΒ  β†’

Last updated about 6 hours ago

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Krishna Mishra

    Thank you so much, Your patch works

    Appreciate so much for your help

  • Status changed to Needs work about 2 years ago
  • πŸ‡ͺπŸ‡ΈSpain eduardo morales alberti Spain, πŸ‡ͺπŸ‡Ί

    Same error here after update to 9.5.x
    In my case I have an extrafield that prints a view.

    In my settings I have

    $config['system.logging']['error_level'] = 'verbose';
    

    The error comes when trying to get the id from the handler on the info array and there is no key id.

  • πŸ‡ͺπŸ‡ΈSpain eduardo morales alberti Spain, πŸ‡ͺπŸ‡Ί

    It is possible that some handlers need to have declared the id.
    Example from https://www.drupal.org/project/broken_link/issues/2986545 β†’

    @@ -24,7 +24,10 @@ class BrokenLinkViewsData extends EntityViewsData {
         $data['broken_link']['table']['group'] = t('Broken links');
     
         // Specify field real column name for additional entity fields.
    -    $data['broken_link__referers']['referers']['filter']['real field'] = 'referers_value';
    +    $data['broken_link__referers']['referers']['filter'] = [
    +      'real field' => 'referers_value',
    +      'id' => 'string',
    +    ];
         $data['broken_link__query_string']['query_string']['filter']['real field'] = 'query_string_value';
         $data['broken_link__referers']['referers']['sort']['real field'] = 'referers_value';
         $data['broken_link__query_string']['query_string']['sort']['real field'] = 'query_string_value';
    
  • πŸ‡ͺπŸ‡ΈSpain eduardo morales alberti Spain, πŸ‡ͺπŸ‡Ί

    I saw that there is a custom text area for no result.
    If I use the core handler, the error is gone, so I will review it.

    use Drupal\views\Plugin\views\area\AreaPluginBase;
    
    /**
     * Defines a views area plugin.
     *
     * @ingroup views_area_handlers
     *
     * @ViewsArea("no_results_message")
     */
    class NoResultsMessage extends AreaPluginBase {
    
      /**
       * {@inheritdoc}
       */
      public function render($empty = FALSE) {
        return [
          '#theme' => 'no_results_message',
        ];
      }
    
    }
    
    
  • Status changed to Active about 2 years ago
  • πŸ‡ͺπŸ‡ΈSpain eduardo morales alberti Spain, πŸ‡ͺπŸ‡Ί

    @Krishna Mishra, @drupalgreenhorn Review if you have custom filters or custom handlers in the view that failed, maybe they are not well implemented.
    In some cases, muting the warning is not the solution.

  • πŸ‡ͺπŸ‡ΈSpain eduardo morales alberti Spain, πŸ‡ͺπŸ‡Ί

    Found the error.
    I found that I have translated the view.
    Example:
    es/views.view.myview.yml

    display:
      default:
        display_options:
    ...
          empty:
            area:
              content:
                value: "<p>Β‘No se han encontrado productos!</p>\r\n"
                format: basic_html
    ...
    

    Original views.view.myview.yml

          empty:
            no_results_message:
              id: no_results_message
              table: views
              field: no_results_message
              relationship: none
              group_type: group
              admin_label: ''
              plugin_id: no_results_message
              empty: true
              content:
                value: '<p>No products found!</p>'
                format: basic_html
              tokenize: false
    

    That seems to be the reason why the display handler does not find the id, the table, or the field. At least in my case.

  • πŸ‡ΊπŸ‡ΈUnited States j_s

    I also encountered this issue and patch #9 helped.

    Now I have some more warnings:

    Warning: Undefined array key "table" in Drupal\views\Plugin\ViewsHandlerManager->getHandler() (line 82 of core/modules/views/src/Plugin/ViewsHandlerManager.php).
    Warning: Undefined array key "field" in Drupal\views\Plugin\ViewsHandlerManager->getHandler() (line 83 of core/modules/views/src/Plugin/ViewsHandlerManager.php).

    I get that it may be some contributed module that isn't implementing something properly. But it might be nice for Drupal to do some isset checks so as to avoid these warnings coming up in log when they don't seemingly affect functionality. Or at least make the error message more useful to help identify what's wrong. As it is, the stack trace doesn't help.

  • πŸ‡¨πŸ‡¦Canada laura.j.johnson@gmail.com Toronto

    In my case there was a broken sort handler in the view. If you take a look at the view in the UI you may be able to see the problem.

  • πŸ‡©πŸ‡ͺGermany cweiske

    I had a hook_views_pre_view function that overrode $view->display_handler options. One of the options I changed did not exist, so the error was indeed helpful that something was wrong with my code.

    function mymod_view_pre_view_article_filter(ViewExecutable $view) {
        $defaults = [...];
        $filters = $view->display_handler->getOption('filters');
        $filters['field_tags_target_id']['value']   = $defaults['tags'];
        $filters['query']['value']                  = $defaults['query']; //this "query" filter did not exist
    }
    
  • πŸ‡§πŸ‡ͺBelgium hoebekewim

    You can fix this in some cases by going to the relevant views, saving it, and also save it's translations.
    Then do a config export and the missing keys will be added to avoid it in the future.

    It is probably caused by updates on Views which were not applied to your config for some reason.

  • πŸ‡ΊπŸ‡ΈUnited States maskedjellybean Portland, OR

    Wow, #20 was the cause of my error as well. No idea how you figured that out based on the error message but I appreciate it!

  • Seeing these in sets of three when trying to apply changes to the VBO field

    Warning: Undefined array key "order_id" in Drupal\views\Plugin\views\HandlerBase->getEntityType() (line 798 of /var/www/html/web/core/modules/views/src/Plugin/views/HandlerBase.php)

    Warning: Trying to access array offset on value of type null in Drupal\views\Plugin\views\HandlerBase->getEntityType() (line 799 of /var/www/html/web/core/modules/views/src/Plugin/views/HandlerBase.php)

    nvalidArgumentException: A valid cache entry key is required. Use getAll() to get all table data. in Drupal\views\ViewsData->get() (line 137 of /var/www/html/web/core/modules/views/src/ViewsData.php).

Production build 0.71.5 2024