From a69343b5b5bfb11a7844460ae03417610a06831c Mon Sep 17 00:00:00 2001 From: Dave Long Date: Mon, 11 Mar 2024 17:13:33 +0000 Subject: [PATCH] Issue #3167126 by ranjith_kumar_k_u, rpayanm, amateescu, mheip, CedricL, smustgrave: Call to a member function getDisplayname() on null in WorkspaceListBuilder.php (cherry picked from commit 0aaa9b8d49a256801ef5bc99071a3881d44f55d4) --- core/modules/workspaces/src/WorkspaceListBuilder.php | 5 ++++- .../workspaces/tests/src/Functional/WorkspaceTest.php | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/modules/workspaces/src/WorkspaceListBuilder.php b/core/modules/workspaces/src/WorkspaceListBuilder.php index 0ed2d9f130e7..958f6f60d7c1 100644 --- a/core/modules/workspaces/src/WorkspaceListBuilder.php +++ b/core/modules/workspaces/src/WorkspaceListBuilder.php @@ -10,6 +10,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Render\RendererInterface; use Drupal\Core\Url; +use Drupal\user\UserInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -121,7 +122,9 @@ class WorkspaceListBuilder extends EntityListBuilder { '#url' => $entity->toUrl(), ], ], - 'owner' => $entity->getOwner()->getDisplayName(), + 'owner' => (($owner = $entity->getOwner()) && $owner instanceof UserInterface) + ? $owner->getDisplayName() + : $this->t('N/A'), ]; $row['data'] = $row['data'] + parent::buildRow($entity); diff --git a/core/modules/workspaces/tests/src/Functional/WorkspaceTest.php b/core/modules/workspaces/tests/src/Functional/WorkspaceTest.php index 29aee8722f90..1f97e5d33a76 100644 --- a/core/modules/workspaces/tests/src/Functional/WorkspaceTest.php +++ b/core/modules/workspaces/tests/src/Functional/WorkspaceTest.php @@ -299,6 +299,16 @@ class WorkspaceTest extends BrowserTestBase { // 'Live' is no longer the active workspace, so it's 'Switch to Live' // operation should be visible now. $assert_session->linkExists('Switch to Live'); + + // Delete any of the workspace owners and visit workspaces listing. + $this->drupalLogin($this->editor2); + user_cancel([], $this->editor1->id(), 'user_cancel_reassign'); + $user = \Drupal::service('entity_type.manager')->getStorage('user')->load($this->editor1->id()); + $user->delete(); + $this->drupalGet('/admin/config/workflow/workspaces'); + $this->assertSession()->pageTextContains('Summer event'); + $summer_event_workspace_row = $page->find('css', 'table tbody tr:nth-of-type(3)'); + $this->assertEquals('N/A', $summer_event_workspace_row->find('css', 'td:nth-of-type(2)')->getText()); } /**