Problem/Motivation
If a user visits a path /node/1234/whatlinkshere, but that node 1234 has been deleted, the user is shown a WSOD with a php error message:
TypeError: Drupal\whatlinkshere\LinkManager::getReferenceContent(): Argument #1 ($entity) must be of type Drupal\Core\Entity\EntityInterface, null given, called in /home/gwulocom/domains/gwulo.com/public_html/web/modules/contrib/whatlinkshere/src/Controller/WhatLinksHereController.php on line 120 in Drupal\whatlinkshere\LinkManager->getReferenceContent() (line 300 of /home/gwulocom/domains/gwulo.com/public_html/web/modules/contrib/whatlinkshere/src/LinkManager.php)
Steps to reproduce
Proposed resolution
Could they see a "404 Page not found" instead?
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 3313430-9.patch | 2.81 KB | Arturo-q |
| #7 | 3313430-7.patch | 1.95 KB | davidhk |
| #6 | NotFoundHttpException.png | 10.3 KB | juancec |
| #4 | 3313430-4.patch | 1.07 KB | Arturo-q |
Issue fork whatlinkshere-3313430
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:
Comments
Comment #2
davidhk commentedComment #3
Arturo-q commentedHi, I will be working on it.
Comment #4
Arturo-q commentedHere is the patch, it should fix the issue.
Moving to needs review.
Comment #5
juancec commentedHI, I'll review it.
Comment #6
juancec commentedAfter applying the patch a 'NotFoundHttpException' exception will be thrown when go to a deleted/inexisting path. So I think it is fixed. Good job @Arturo1007. Moving it to RTBC.
Comment #7
davidhk commentedThank you for the quick response.
I've since seen the same problem happen with a media entity, and I guess the same will happen with taxonomy terms too, so I've also added the change from #4 to the taxonomyTerm() and media() functions in the attached patch.
Comment #8
johan.gant commentedThis is great, thanks. Something I've seen across other contrib modules as a more reliable check for loaded entity values is the use of the instanceof test rather than just a check for null. For example, instead of:
try this:
You would need to add the required use namespace declaration, and ensure the interface or class instance used matches what you expect to be returned. This process helps with static analysis tools such as phpstan and IDEs like PHPStorm's indexing/symbol map, which all make a for more productive development experience.
Comment #9
Arturo-q commentedHey, okay, got it, I will be working on it.
Comment #10
Arturo-q commentedHi, I've made the changes pointed on #8,
I also made the validations with media and Taxonomy like this:
Kindly review it.
Regards!.
Comment #11
johan.gant commentedLooks good to me, thanks!
Comment #15
omahmMerged into dev. Thanks all.