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 0aaa9b8d49)
merge-requests/6829/merge
Dave Long 2024-03-11 17:13:33 +00:00
parent c05a5c1a7c
commit a69343b5b5
No known key found for this signature in database
GPG Key ID: ED52AE211E142771
2 changed files with 14 additions and 1 deletions

View File

@ -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);

View File

@ -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());
}
/**