Commit 0b5f5ce8 authored by alexpott's avatar alexpott

Issue #1768526 by swentel, Berdir: NodeFormController::validate() calls buildEntity() twice

parent 4f33bd49
......@@ -76,6 +76,7 @@ public function validate(array $form, FormStateInterface $form_state) {
// Execute legacy global validation handlers.
$form_state->setValidateHandlers([]);
\Drupal::service('form_validator')->executeValidateHandlers($form, $form_state);
return $entity;
}
/**
......
......@@ -101,6 +101,9 @@ public function buildEntity(array $form, FormStateInterface $form_state);
* A nested array form elements comprising the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return \Drupal\Core\Entity\ContentEntityTypeInterface
* The built entity.
*/
public function validate(array $form, FormStateInterface $form_state);
......
......@@ -287,8 +287,7 @@ public function buildEntity(array $form, FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state) {
parent::validate($form, $form_state);
$comment = $this->buildEntity($form, $form_state);
$comment = parent::validate($form, $form_state);
// Customly trigger validation of manually added fields and add in
// violations.
......@@ -300,6 +299,8 @@ public function validate(array $form, FormStateInterface $form_state) {
foreach ($violations as $violation) {
$form_state->setErrorByName('name', $violation->getMessage());
}
return $comment;
}
/**
......
......@@ -292,13 +292,13 @@ protected function actions(array $form, FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state) {
$node = $this->buildEntity($form, $form_state);
$node = parent::validate($form, $form_state);
if ($node->id() && (node_last_changed($node->id(), $this->getFormLangcode($form_state)) > $node->getChangedTime())) {
$form_state->setErrorByName('changed', $this->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.'));
}
parent::validate($form, $form_state);
return $node;
}
/**
......
......@@ -383,10 +383,9 @@ public function buildEntity(array $form, FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state) {
parent::validate($form, $form_state);
/** @var \Drupal\user\UserInterface $account */
$account = $this->buildEntity($form, $form_state);
$account = parent::validate($form, $form_state);
// Customly trigger validation of manually added fields and add in
// violations. This is necessary as entity form displays only invoke entity
// validation for fields contained in the display.
......@@ -406,6 +405,8 @@ public function validate(array $form, FormStateInterface $form_state) {
$form_state->setErrorByName($field_name, $violation->getMessage());
}
}
return $account;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment