Problem/Motivation
Linked with #3511997: Allow deleting Content Template entity without deleting source Node, upon deleting a Content Template at /admin/content/template, I get the following error:
The website encountered an unexpected error. Try again later.
TypeError: Drupal\Core\Entity\EntityListBuilder::getOperations(): Argument #1 ($entity) must be of type Drupal\Core\Entity\EntityInterface, null given, called in /app/web/modules/contrib/content_templates/src/ContentTemplateListBuilder.php on line 47 in Drupal\Core\Entity\EntityListBuilder->getOperations() (line 131 of core/lib/Drupal/Core/Entity/EntityListBuilder.php).
Drupal\content_templates\ContentTemplateListBuilder->getOperations(Object) (Line: 242)
Drupal\Core\Entity\EntityListBuilder->buildOperations(Object) (Line: 224)
Drupal\Core\Entity\EntityListBuilder->buildRow(Object) (Line: 39)
Drupal\content_templates\ContentTemplateListBuilder->buildRow(Object) (Line: 272)
Drupal\Core\Entity\EntityListBuilder->render() (Line: 23)
Drupal\Core\Entity\Controller\EntityListController->listing('content_template')
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 593)
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: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 54)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle(Object, 1, 1) (Line: 53)
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: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 53)
Asm89\Stack\Cors->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: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Steps to reproduce
- Set a Node as a Content Template
- Remove the Content Template in the UI
Proposed resolution
Implement better null handling, especially after the delete action if no other Content Templates remain.
Remaining tasks
Fix, review and test.
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Comments
Comment #2
baikho commentedComment #3
a.dmitriiev commentedSorry, but I can't reproduce the issue. The error trace says the problem is in line:
But $entity there is the entity from the list row. And the method
getOperationsis even type hinted, so are you sure you haven't made any modifications to that file?