- Issue created by @omar_emailat
- 🇮🇳India narendraR Jaipur, India
Did you face this issue in fresh Drupal install? If yes, please update steps to reproduce in issue.
This might be possible due to some custom code also. - Status changed to Postponed: needs info
about 1 year ago 3:16pm 14 August 2023 - 🇺🇸United States RustedBucket
Currently battling this same issue. Trying to override a view template from a custom module.
Basically I want to override the themes views_view_unformatted.html.twig templateMy custom template resides in modules/custom/custom_app/templates/views-view--on-campus-numbers.html.twig
In my custom_app.module file I have the following:function custom_app_theme_suggestions_alter(array &$suggestions, array $variables, $hook) { if ($hook == 'views_view_unformatted') { $suggestions[] = 'views-view--on-campus-numbers'; } } function custom_app_theme($existing, $type, $theme, $path) { return [ 'views_view__on_campus_numbers' => [ 'base_hook' => 'views_view_unformatted', ] ]; }
This throws 2 errors:
Warning: Undefined array key "render element" in Drupal\Core\Theme\ThemeManager->render() (line 199 of core/lib/Drupal/Core/Theme/ThemeManager.php).
Drupal\Core\Theme\ThemeManager->render('views_view__on_campus_numbers', Array) (Line: 436)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 449)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 583)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 239)
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: 187)
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: 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: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)Warning: Undefined array key "render element" in Drupal\Core\Theme\ThemeManager->render() (line 201 of core/lib/Drupal/Core/Theme/ThemeManager.php).
Drupal\Core\Theme\ThemeManager->render('views_view__on_campus_numbers', Array) (Line: 436)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 449)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 583)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 239)
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: 187)
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: 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: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)Adding 'render element' => 'elements' like this makes the error go away but no output from the view is rendered
'views_view__on_campus_numbers' => [ 'render element' => 'elements', 'base_hook' => 'views_view_unformatted', ]
- 🇳🇱Netherlands florisg
Thank you omar_emailat, this patch helped us,
it's simply checking the `render element` exists.
this works in our case at Drupal 9.5.11 and does not add much overhead.
So we can deal with custom cleaning scheduled and unsurprised. - Status changed to Closed: won't fix
7 months ago 9:21am 3 April 2024 - 🇪🇸Spain eduardo morales alberti Spain, 🇪🇺
Patch #2 is not right because it mascarade the problem and it does not solve it.
After some debugging, we saw that the theme function did not have the variables as array.
Before:function mymodule_theme($existing, $type, $theme, $path) { return [ 'mymodule_test' => [ 'variables' => NULL, ], ]; }
ThemeManager.php sets the 'render element' with the same value as the variables but its expects an array.
if (isset($variables['#theme']) || isset($variables['#theme_wrappers'])) { $element = $variables; $variables = []; if (isset($info['variables'])) { foreach (array_keys($info['variables']) as $name) { if (\array_key_exists("#$name", $element)) { $variables[$name] = $element["#$name"]; } } } else { $variables[$info['render element']] = $element; // Give a hint to render engines to prevent infinite recursion. $variables[$info['render element']]['#render_children'] = TRUE; } }
Solution:
function mymodule_theme($existing, $type, $theme, $path) { return [ 'mymodule_test' => [ 'variables' => [], ], ]; }