function NodeTestHooks::nodeInsert

Implements hook_ENTITY_TYPE_insert() for node entities.

This tests saving a node on node insert.

See also

\Drupal\node\Tests\NodeSaveTest::testNodeSaveOnInsert()

File

core/modules/node/tests/modules/node_test/src/Hook/NodeTestHooks.php, line 183

Class

NodeTestHooks
Hook implementations for node_test.

Namespace

Drupal\node_test\Hook

Code

public function nodeInsert(NodeInterface $node) {
    // Set the node title to the node ID and save.
    if ($node->getTitle() == 'new') {
        $node->setTitle('Node ' . $node->id());
        $node->setNewRevision(FALSE);
        $node->save();
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.