Skip to content
Snippets Groups Projects

Issue #3161212 by asubit, eduardo morales alberti, sandeepsingh199: Node add/edit gives a Call to a member function getAccountName() on null Drupal 11

Closed 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
Closed Joseph Olstad requested to merge issue/drupal-3161212:3161212-node-add-gives into 11.1.x
1 unresolved thread

Issue #3161212 by asubit, eduardo morales alberti, sandeepsingh199: Node add/edit gives a Call to a member function getAccountName() on null Drupal 11

Closes #3161212

Edited by Joseph Olstad

Merge request reports

Approval is optional
Code Quality is loading
Test summary results are being parsed

Closed by Adam BramleyAdam Bramley 7 hours ago (Apr 8, 2025 4:24am UTC)

Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Joseph Olstad changed target branch from 11.x to 11.1.x

    changed target branch from 11.x to 11.1.x

  • Joseph Olstad changed title from Issue #3484247 by mstrelan, smustgrave: Add NodeElement return typehints to... to Issue #3161212 by asubit, eduardo morales alberti, sandeepsingh199: Node add/edit gives a Call to a member function getAccountName() on null Drupal 11

    changed title from Issue #3484247 by mstrelan, smustgrave: Add NodeElement return typehints to... to Issue #3161212 by asubit, eduardo morales alberti, sandeepsingh199: Node add/edit gives a Call to a member function getAccountName() on null Drupal 11

  • Joseph Olstad changed the description

    changed the description

  • Joseph Olstad added 1 commit

    added 1 commit

    Compare with previous version

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() since currentUser 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
  • closed

  • Please register or sign in to reply
    Loading