function hook_validate

Perform node validation before a node is created or updated.

This hook is invoked only on the module that defines the node's content type (use hook_node_validate() to act on all node validations).

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 before hook_node_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.

Parameters

\Drupal\Core\Entity\EntityInterface $node: The node being validated.

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

$form_state: The form state array.

Related topics

69 functions implement hook_validate()

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

aggregator_form_category_validate in drupal/core/modules/aggregator/aggregator.admin.inc
Form validation handler for aggregator_form_category().
authorize_filetransfer_form_validate in drupal/core/includes/authorize.inc
Form validation handler for authorize_filetransfer_form().
book_admin_edit_validate in drupal/core/modules/book/book.admin.inc
Form validation handler for book_admin_edit().
color_scheme_form_validate in drupal/core/modules/color/color.module
Form validation handler for color_scheme_form().
comment_admin_overview_validate in drupal/core/modules/comment/comment.admin.inc
Form validation handler for comment_admin_overview().

... See full list

File

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

Code

function hook_validate(\Drupal\Core\Entity\EntityInterface $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.'));
    }
  }
}