Problem/Motivation

Displaying a warning on top of page. Although below the warning, the switcher seems to work fine.
Only one view is showing this message. All other views using display switch do not show such warning.

Steps to reproduce

Duplicate current view using views display switch.
Edit block parameters as needed.

I have 5 different views using this method and all work fine with no errors or warning since all use the same block names "grid" and "list" for the twig to work. One view however shows fine, but when you click on the icon to switch view, it displays this warning, not sure why it does it only to one view when all others created and edited identically the same don't throw any message. Also, note that the actual view does work, it displays the grid and list perfectly below the message, nothing seems to be bad, except for this unnecessary message...

User warning: setDisplay() called with invalid display ID "list". in Drupal\views\ViewExecutable->setDisplay() (line 802 of core/modules/views/src/ViewExecutable.php).
Drupal\views\ViewExecutable->setDisplay('list') (Line: 73)
views_display_switch_views_pre_view(Object, 'block_4', Array)
call_user_func_array('views_display_switch_views_pre_view', Array) (Line: 403)
Drupal\Core\Extension\ModuleHandler->invokeAll('views_pre_view', Array) (Line: 1686)
Drupal\views\ViewExecutable->preExecute(Array) (Line: 1627)
Drupal\views\ViewExecutable->executeDisplay('block_4', Array) (Line: 77)
Drupal\views\Element\View::preRenderViewElement(Array) (Line: 59)
Drupal\views\Plugin\Block\ViewsBlock->build() (Line: 105)
Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray->onBuildRender(Object, 'section_component.build.render_array', Object)
call_user_func(Array, Object, 'section_component.build.render_array', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'section_component.build.render_array') (Line: 90)
Drupal\layout_builder\SectionComponent->toRenderArray(Array, ) (Line: 86)
Drupal\layout_builder\Section->toRenderArray(Array) (Line: 317)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->buildSections(Object) (Line: 276)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->buildMultiple(Array) (Line: 340)
Drupal\Core\Entity\EntityViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 24)
Drupal\node\NodeViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 282)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 239)
Drupal\Core\Entity\EntityViewBuilder->build(Array)
call_user_func_array(Array, Array) (Line: 101)
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: 781)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 372)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
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: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->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: 57)
Drupal\advban\AdvbanMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 706)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Proposed resolution

Id of Grid view block is "grid" and id of List view block is "list". No idea where "block_4" is coming from. I have tried "drush cr", clear cache, clear all cache, etc and nothing.

Is there a way to suppress these messages with a patch or something? Everything works fine except for this annoying message that shows above the page content. If I remove Views Display Switch from the view the message goes away so it is directly related to this module. Cannot have the public seeing this message.

User interface changes

I created a custom twig...

<div class="views-display-switch">
  <a href="{{ links.grid['#url'] }}" title="{{ links.grid['#title'] }}" {{ create_attribute(links.grid['#options'].attributes) }} role="button"><i class="fa fa-th-large"></i> Grid</a>

  <a href="{{ links.list['#url'] }}" title="{{ links.list['#title'] }}" {{ create_attribute(links.list['#options'].attributes) }} role="button"><i class="fa fa-bars"></i> List</a>
</div>

Although message still shows when I remove this twig and use the default provided by module so I dont think it has anything to do with the twig.

Thank you.

Comments

jsidigital created an issue. See original summary.

jsidigital’s picture

Okay I found the problem.

Apparently I had other blocks that were showing on this same page from the same view that contained the "View Display Switch".
Problem was that on one of the other views, it had the Global Display Switch enabled (when I added them at first, I accidentally applied to ALL blocks. Since this block had that on its header, there were 3 blocks on this same page trying to read the Display Switch module and since this fourth block was not supposed to have it, it generated these errors.

Once I removed the Global Display Switch from that 3rd block, it all worked fine.

So if anyone gets any warnings or errors like this, make sure other blocks/views on that same page do not have the Display Switch if they do not need it. Seems like I fell victim of that drupal view (this block only) dropdown mistake.

jsidigital’s picture

Status: Active » Closed (works as designed)