Problem/Motivation
In drupal 10, in developer environment with PHP assert enabled, on initial revision created, a user with ID NULL is tried to fetch.
```
The website encountered an unexpected error. Try again later.
AssertionError: Cannot load the "user" entity with NULL ID. in assert() (line 261 of core/lib/Drupal/Core/Entity/EntityStorageBase.php).
Drupal\Core\Entity\EntityStorageBase->load(NULL) (Line: 255)
Drupal\taxonomy_term_revision\Controller\TermRevisionController->getRevisionUser(NULL) (Line: 155)
Drupal\taxonomy_term_revision\Controller\TermRevisionController->getRevisions(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
```
Steps to reproduce
Enable assert in local dev environment with PHP (as it *should* be)
Proposed resolution
Test in code for a user id f NULL and make it the anonymous user, no need to fetch.
```
21:25 $ diff -u ./TermRevisionController.php.ori ./TermRevisionController.php
--- ./TermRevisionController.php.ori 2024-07-09 21:23:26.854999955 +0800
+++ ./TermRevisionController.php 2024-07-09 21:24:12.316946865 +0800
@@ -252,11 +252,10 @@
* Returns link with the revision user's name.
*/
protected function getRevisionUser(?string $revision_user): Link {
- $user = $this->userStorage->load($revision_user);
- if (empty($user)) {
+ if (empty($revision_user)) {
return Link::fromTextAndUrl($this->t('Anonymous'), Url::fromUri('internal:/user/' . $revision_user));
}
-
+ $user = $this->userStorage->load($revision_user);
return Link::fromTextAndUrl($user->get('name')->getString(), Url::fromUri('internal:/user/' . $revision_user));
}
```