function hook_node_create

Act on a newly created node.

This hook runs after a new node object has just been instantiated. It can be used to set initial values, e.g. to provide defaults.

Parameters

\Drupal\Core\Entity\EntityInterface $node: The node object.

Related topics

1 function implements hook_node_create()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

entity_crud_hook_test_node_create in drupal/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module
Implements hook_node_create().
3 invocations of hook_node_create()
ConfigStorageController::create in drupal/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php
Implements Drupal\Core\Entity\EntityStorageControllerInterface::create().
DatabaseStorageController::create in drupal/core/lib/Drupal/Core/Entity/DatabaseStorageController.php
Implements \Drupal\Core\Entity\EntityStorageControllerInterface::create().
DatabaseStorageControllerNG::create in drupal/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php
Overrides DatabaseStorageController::create().

File

drupal/core/modules/node/node.api.php, line 501
Hooks provided by the Node module.

Code

function hook_node_create(\Drupal\Core\Entity\EntityInterface $node) {
  if (!isset($node->foo)) {
    $node->foo = 'some_initial_value';
  }
}