Call to a member function getDisplayName() on null

Created on 27 March 2021, over 3 years ago
Updated 11 April 2024, 3 months ago

Problem/Motivation

On my website, when I go to the revisions for a node:
https://www.example.org/node/2959/revisions/view/38665/39409/split_fields

We get the following error

Call to a member function getDisplayName() on null
in Drupal\diff\DiffLayoutBase->buildRevisionData()
line 182 of modules/contrib/diff/src/DiffLayoutBase.php

The problem is that $revision->getRevisionUser() is returning null.

This is a probably a case of bad data on my site, but I attach my patch here in case someone finds it useful.

The fix is simply to do a check for null:

$revision_link['author'] = [
  '#type' => 'link',
  '#title' => ($revision_user = $revision->getRevisionUser()) ? $revision_user->getDisplayName() : '',
πŸ“Œ Task
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany michaellenahan

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.

Production build 0.69.0 2024