Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Title works as expected when enabled for a content type. After saving a node, or clearing cache while viewing a node, the following error is shown:
Notice: Undefined index: title in template_preprocess_node() (line 604 of core/modules/node/node.module).
template_preprocess_node(Array, 'node', Array) (Line: 287)
Drupal\Core\Theme\ThemeManager->render('node', Array) (Line: 435)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 149)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
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: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
It looks like template_preprocess_node() is missing the $variables['elements']['title']
even though there appears to be a section in title.module
to deal with this.
Comments
Comment #2
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedIf you look at the code for title_entity_prepare_view this function has an explanatory comment and code that should workaround the error that you are seeing.
The workaround worked for me, except when I enabled the D8.4 experimental "Field Layout" module. Are you using that or a similar module?
Comment #3
AdamPS CreditAttribution: AdamPS at AlbanyWeb commentedComment #4
bserem CreditAttribution: bserem at zehnplus commentedIn my case, I use the field_layout module and I can verify that this problem exists.
Comment #5
kevineinarsson CreditAttribution: kevineinarsson as a volunteer commentedI also came across this issue, and in my case it was because I missed to call the
#pre_render
:I used node_view_multiple() and moved the individual nodes to where I wanted to render them.
#pre_render
is set on the render array itself and not on the node render arrays. Because of this I was missing a lot of variables in my render arrays. I assume setting the correct#pre_render
on the nodes would solve it too.Comment #6
RomixuaComment #7
Romixua