Issue #3161212 by asubit, eduardo morales alberti, sandeepsingh199: Node add/edit gives a Call to a member function getAccountName() on null Drupal 11
1 unresolved thread
Edited by Joseph Olstad
Merge request reports
Activity
added 1 commit
139 139 140 140 $form['advanced']['#attributes']['class'][] = 'entity-meta'; 141 141 142 // Set default author. 143 $meta_author = \Drupal::currentUser()->getAccountName(); 144 if (!$node->isNew() && $node->getOwner() != NULL) { 145 $meta_author = $node->getOwner()->getAccountName(); 146 } 142 147 $form['meta'] = [ Avoid
\Drupal::currentUser()
sincecurrentUser
is already available through dependency injection.Maybe the check can be changed as below,
+ // Set default author. + $meta_author = $node->getOwner() instanceof \Drupal\user\UserInterface + ? $node->getOwner()->getAccountName() + : $this->currentUser()->getAccountName();
Please register or sign in to reply