Overrides Drupal\Core\Entity\EntityFormController::validate().
Overrides EntityFormController::validate
public function validate(array $form, array &$form_state) {
$node = $this
->buildEntity($form, $form_state);
if (isset($node->nid) && node_last_changed($node->nid, $this
->getFormLangcode($form_state)) > $node->changed) {
form_set_error('changed', t('The content on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved.'));
}
// Validate the "authored by" field.
if (!empty($node->name) && !($account = user_load_by_name($node->name))) {
// The use of empty() is mandatory in the context of usernames
// as the empty string denotes the anonymous user. In case we
// are dealing with an anonymous user we set the user ID to 0.
form_set_error('name', t('The username %name does not exist.', array(
'%name' => $node->name,
)));
}
// Validate the "authored on" field.
// The date element contains the date object.
$date = $node->date instanceof DrupalDateTime ? $node->date : new DrupalDateTime($node->date);
if ($date
->hasErrors()) {
form_set_error('date', t('You have to specify a valid date.'));
}
// Invoke hook_validate() for node type specific validation and
// hook_node_validate() for miscellaneous validation needed by modules.
// Can't use node_invoke() or module_invoke_all(), because $form_state must
// be receivable by reference.
if ($function = node_hook($node->type, 'validate')) {
$function($node, $form, $form_state);
}
foreach (module_implements('node_validate') as $module) {
$function = $module . '_node_validate';
$function($node, $form, $form_state);
}
parent::validate($form, $form_state);
}