Call to a member function getMode() on null

Created on 8 October 2024, 2 months ago

Problem/Motivation

On a project that did not have edit_plus or lb_plus or toolbar_plus installed, I added only the edit_plus module like this:
composer require 'drupal/edit_plus:1.0.x-dev@dev'
That command also downloaded toolbar_plus 1.0.0-alpha3.
Then I enabled the module via:
drush en edit_plus
It requested: The following module(s) will be installed: edit_plus, toolbar_plus to which I used Yes to continue. Then edit_plus and toolbar_plus were successfully installed. Now when I visit the homepage of my project, which is a Layout Builder enabled node type, I get this error:
Call to a member function getMode() on null

It seems to happen only on layoutbuilder block types that have no fields, like our custom block type 'horizontal line'.

Steps to reproduce

Contained in the info above.

Proposed resolution

I tried to change

  $cached_view_modes[$original_id] = $view_display->getMode();
  return $cached_view_modes[$original_id];

into:

  if ($view_display) {
    $cached_view_modes[$original_id] = $view_display->getMode();
  }
  return $cached_view_modes[$original_id];

But then I got another error:
_toolbar_plus_get_view_mode(): Return value must be of type string, null returned
Which I temporary resolved by changing
return $cached_view_modes[$original_id];
into:
return $cached_view_modes[$original_id] ?? 'default';

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium flyke

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

Comments & Activities

Production build 0.71.5 2024