function hook_node_validate

Perform node validation before a node is created or updated.

This hook is invoked from NodeFormController::validate(), after a user has finished editing the node and is previewing or submitting it. It is invoked at the end of all the standard validation steps, and after the type-specific hook_validate() is invoked.

To indicate a validation error, use form_set_error().

Note: Changes made to the $node object within your hook implementation will have no effect. The preferred method to change a node's content is to use hook_node_presave() instead. If it is really necessary to change the node at the validate stage, you can use form_set_value().

Parameters

Drupal\node\Node $node: The node being validated.

$form: The form being used to edit the node.

$form_state: The form state array.

Related topics

2 functions implement hook_node_validate()

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

forum_node_validate in drupal/core/modules/forum/forum.module
Implements hook_node_validate().
translation_node_validate in drupal/core/modules/translation/translation.module
Implements hook_node_validate().
1 invocation of hook_node_validate()

File

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

Code

function hook_node_validate(Drupal\node\Node $node, $form, &$form_state) {
  if (isset($node->end) && isset($node->start)) {
    if ($node->start > $node->end) {
      form_set_error('time', t('An event may not end before it starts.'));
    }
  }
}