Issue #3161212 by joseph.olstad, acbramley, asubit, eduardo morales alberti, sandeepsingh199, berdir, catch: Node add/edit gives a Call to a member function getAccountName() on null when author is NULL
(cherry picked from commit ca57f2128a
)
merge-requests/12078/head
parent
8c7ffa560b
commit
b174fb0932
|
@ -163,7 +163,7 @@ class NodeForm extends ContentEntityForm {
|
||||||
$form['meta']['author'] = [
|
$form['meta']['author'] = [
|
||||||
'#type' => 'item',
|
'#type' => 'item',
|
||||||
'#title' => $this->t('Author'),
|
'#title' => $this->t('Author'),
|
||||||
'#markup' => $node->getOwner()->getAccountName(),
|
'#markup' => $node->getOwner()?->getAccountName(),
|
||||||
'#wrapper_attributes' => ['class' => ['entity-meta__author']],
|
'#wrapper_attributes' => ['class' => ['entity-meta__author']],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
name: 'Node no default author'
|
||||||
|
type: module
|
||||||
|
description: 'Disables the default value callback for the uid field on node.'
|
||||||
|
package: Testing
|
||||||
|
version: VERSION
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Drupal\node_no_default_author\Hook;
|
||||||
|
|
||||||
|
use Drupal\Core\Entity\EntityTypeInterface;
|
||||||
|
use Drupal\Core\Hook\Attribute\Hook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook implementations for node_no_default_author.
|
||||||
|
*/
|
||||||
|
class NodeNoDefaultAuthorHooks {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_entity_base_field_info_alter().
|
||||||
|
*/
|
||||||
|
#[Hook('entity_base_field_info_alter')]
|
||||||
|
public function entityBaseFieldInfoAlter(&$fields, EntityTypeInterface $entity_type): void {
|
||||||
|
if ($entity_type->id() === 'node') {
|
||||||
|
$fields['uid']->setDefaultValueCallback(static::class . '::noDefaultAuthor');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An empty callback to set for the default value callback of uid.
|
||||||
|
*/
|
||||||
|
public static function noDefaultAuthor(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -258,6 +258,16 @@ class NodeEditFormTest extends NodeTestBase {
|
||||||
$this->assertSession()->pageTextContains($this->container->get('date.formatter')->format($node->getChangedTime(), 'short'));
|
$this->assertSession()->pageTextContains($this->container->get('date.formatter')->format($node->getChangedTime(), 'short'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the node form when the author is NULL.
|
||||||
|
*/
|
||||||
|
public function testNodeFormNullAuthor(): void {
|
||||||
|
\Drupal::service('module_installer')->install(['node_no_default_author']);
|
||||||
|
$this->drupalLogin($this->adminUser);
|
||||||
|
$this->drupalGet('node/add/page');
|
||||||
|
$this->assertSession()->statusCodeEquals(200);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks that the "authored by" works correctly with various values.
|
* Checks that the "authored by" works correctly with various values.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue