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() : '',
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | diff-3206057-11.patch | 1.45 KB | martijn de wit |
| #7 | diff-3206057-7.patch | 1.47 KB | mingsong |
| #4 | 3206057-4.patch | 670 bytes | michaellenahan |
Issue fork diff-3206057
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3206057-call-to-a
changes, plain diff MR !6
Comments
Comment #2
michaellenahan commentedComment #4
michaellenahan commentedAdding the patch manually here, in addition to the Merge Request.
We're using cweagans/composer-patches in our composer.json - so we will use the url https://www.drupal.org/files/issues/2021-03-27/3206057-4.patch in our composer.json
A method for using gitlab merge requests for patch management is still being worked on here - https://www.drupal.org/project/drupalorg/issues/3204538
Comment #5
michaellenahan commentedComment #6
mingsongIn the revisions table, the user name for NULL is 'Anonymous (not verified)'. So I suggest using the same name rather than '' for the consistency.
Here is the patch.
I am happy to push it to the PR created for this issue. Just let me know what you think.
Comment #7
mingsongSorry, patch from #6 was failed from the test.
Here is the new one.
Comment #8
michaellenahan commentedYes, that's a good improvement I think.
Comment #9
mingsongUnfortunately, I don't have the access to push code to the repository.
I attach the git diff code here, in case you want to push it back to your repository.
Comment #10
mingsongMy contribute module to compare revisions for entity types other than Node.
https://www.drupal.org/project/entity_diff_ui
This module fixes this issue too.
Comment #11
martijn de witPatch from #7 doens't apply anymore to 8.x-1.1 / 8.x-1.dev
Made new patch
Comment #12
martijn de witUsernames can be empty due cancelation. We had this at certain entities.
This is still a issue with media entities, see: #3043725: Provide a Entity Handler for user cancelation
Comment #13
adriancidThis fixed the issue for me on a project I'm working now.
Comment #14
caspervoogt commented#11 worked for me
Comment #15
gngn commented#11 worked for me too.
In my case the revision user had been deleted (so
getDisplayName()was called on null).Comment #16
acbramley commentedThis is a duplicate of #3088274: Prevent fatal error if the revision has no author
Comment #18
mvnovick commentedThe problem with anonymous user still persists, and patch #11 still works in Drupal 10.3.
Comment #19
opiUse -dev version of diff module solve the same issue for me. The fix from #3167126 is commited but no release has been made.
Comment #20
acbramley commented@opi or upgrade to Diff v2 :) 8.x-1.x is essentially obselete