diff --git a/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php b/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php
index 3583ad4..f3a23a7 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php
@@ -121,6 +121,7 @@ public function delete(array $form, FormStateInterface $form_state) {}
public function validateForm(array &$form, FormStateInterface $form_state) {
// Override the default validation implementation as it is not necessary
// nor possible to validate an entity in a confirmation form.
+ return $this->buildEntity($form, $form_state);
}
}
diff --git a/core/lib/Drupal/Core/Entity/ContentEntityForm.php b/core/lib/Drupal/Core/Entity/ContentEntityForm.php
index bcbcc31..cbeea5f 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityForm.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityForm.php
@@ -64,18 +64,6 @@ public function form(array $form, FormStateInterface $form_state) {
/**
* {@inheritdoc}
- *
- * Note that extending classes should not override this method to add entity
- * validation logic, but define further validation constraints using the
- * entity validation API and/or provide a new validation constraint if
- * necessary. This is the only way to ensure that the validation logic
- * is correctly applied independently of form submissions; e.g., for REST
- * requests.
- * For more information about entity validation, see
- * https://www.drupal.org/node/2015613.
- *
- * @return \Drupal\Core\Entity\ContentEntityTypeInterface
- * The built entity.
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
diff --git a/core/lib/Drupal/Core/Entity/ContentEntityFormInterface.php b/core/lib/Drupal/Core/Entity/ContentEntityFormInterface.php
index 4f130dc..52023a2 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityFormInterface.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityFormInterface.php
@@ -61,4 +61,21 @@ public function getFormLangcode(FormStateInterface $form_state);
*/
public function isDefaultFormLangcode(FormStateInterface $form_state);
+ /**
+ * {@inheritdoc}
+ *
+ * Note that extending classes should not override this method to add entity
+ * validation logic, but define further validation constraints using the
+ * entity validation API and/or provide a new validation constraint if
+ * necessary. This is the only way to ensure that the validation logic
+ * is correctly applied independently of form submissions; e.g., for REST
+ * requests.
+ * For more information about entity validation, see
+ * https://www.drupal.org/node/2015613.
+ *
+ * @return \Drupal\Core\Entity\ContentEntityTypeInterface
+ * The built entity.
+ */
+ public function validateForm(array &$form, FormStateInterface $form_state);
+
}
diff --git a/core/modules/action/src/ActionFormBase.php b/core/modules/action/src/ActionFormBase.php
index 96bb63d..9afb094 100644
--- a/core/modules/action/src/ActionFormBase.php
+++ b/core/modules/action/src/ActionFormBase.php
@@ -123,8 +123,8 @@ protected function actions(array $form, FormStateInterface $form_state) {
/**
* {@inheritdoc}
*/
- public function validate(array $form, FormStateInterface $form_state) {
- parent::validate($form, $form_state);
+ public function validateForm(array &$form, FormStateInterface $form_state) {
+ parent::validateForm($form, $form_state);
if ($this->plugin instanceof PluginFormInterface) {
$this->plugin->validateConfigurationForm($form, $form_state);
diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php
index 08d7508..2ba16be 100644
--- a/core/modules/block/src/BlockForm.php
+++ b/core/modules/block/src/BlockForm.php
@@ -273,8 +273,8 @@ protected function actions(array $form, FormStateInterface $form_state) {
/**
* {@inheritdoc}
*/
- public function validate(array $form, FormStateInterface $form_state) {
- parent::validate($form, $form_state);
+ public function validateForm(array &$form, FormStateInterface $form_state) {
+ parent::validateForm($form, $form_state);
// The Block Entity form puts all block plugin form elements in the
// settings form element, so just pass that to the block for validation.
diff --git a/core/modules/block_content/src/BlockContentForm.php b/core/modules/block_content/src/BlockContentForm.php
index 379e576..ec267cc 100644
--- a/core/modules/block_content/src/BlockContentForm.php
+++ b/core/modules/block_content/src/BlockContentForm.php
@@ -224,7 +224,8 @@ public function save(array $form, FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
- if ($this->entity->isNew()) {
+ $entity = parent::validateForm($form, $form_state);
+ if ($entity->isNew()) {
$exists = $this->blockContentStorage->loadByProperties(array('info' => $form_state->getValue(['info', 0, 'value'])));
if (!empty($exists)) {
$form_state->setErrorByName('info', $this->t('A block with description %name already exists.', array(
@@ -232,6 +233,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
)));
}
}
+ return $entity;
}
}
diff --git a/core/modules/contact/src/ContactFormEditForm.php b/core/modules/contact/src/ContactFormEditForm.php
index 3300c59..c545b0e 100644
--- a/core/modules/contact/src/ContactFormEditForm.php
+++ b/core/modules/contact/src/ContactFormEditForm.php
@@ -112,8 +112,8 @@ public function form(array $form, FormStateInterface $form_state) {
/**
* {@inheritdoc}
*/
- public function validate(array $form, FormStateInterface $form_state) {
- parent::validate($form, $form_state);
+ public function validateForm(array &$form, FormStateInterface $form_state) {
+ parent::validateForm($form, $form_state);
// Validate and each email recipient.
$recipients = explode(',', $form_state->getValue('recipients'));
diff --git a/core/modules/contact/src/MessageForm.php b/core/modules/contact/src/MessageForm.php
index d77e3d3..27352c7 100644
--- a/core/modules/contact/src/MessageForm.php
+++ b/core/modules/contact/src/MessageForm.php
@@ -168,6 +168,7 @@ public function actions(array $form, FormStateInterface $form_state) {
$elements = parent::actions($form, $form_state);
$elements['submit']['#value'] = $this->t('Send message');
$elements['preview'] = array(
+ '#type' => 'submit',
'#value' => $this->t('Preview'),
'#submit' => array('::submitForm', '::preview'),
);
diff --git a/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php b/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php
index d6d801b..350a2e9 100644
--- a/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php
+++ b/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php
@@ -38,8 +38,8 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t
/**
* {@inheritdoc}
*/
- public function validate(array $form, FormStateInterface $form_state) {
- parent::validate($form, $form_state);
+ public function validateForm(array &$form, FormStateInterface $form_state) {
+ parent::validateForm($form, $form_state);
$form_state->setValueForElement($form['id'], $this->targetEntityTypeId . '.' . $form_state->getValue('id'));
}
diff --git a/core/modules/field_ui/src/Form/FieldConfigEditForm.php b/core/modules/field_ui/src/Form/FieldConfigEditForm.php
index 8a3cd54..b759739 100644
--- a/core/modules/field_ui/src/Form/FieldConfigEditForm.php
+++ b/core/modules/field_ui/src/Form/FieldConfigEditForm.php
@@ -150,8 +150,8 @@ protected function actions(array $form, FormStateInterface $form_state) {
/**
* {@inheritdoc}
*/
- public function validate(array $form, FormStateInterface $form_state) {
- parent::validate($form, $form_state);
+ public function validateForm(array &$form, FormStateInterface $form_state) {
+ parent::validateForm($form, $form_state);
if (isset($form['default_value'])) {
$item = $form['#entity']->get($this->entity->getName());
diff --git a/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php
index 58c4ea9..adafcc7 100644
--- a/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php
+++ b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php
@@ -146,8 +146,8 @@ protected function actions(array $form, FormStateInterface $form_state) {
/**
* {@inheritdoc}
*/
- public function validate(array $form, FormStateInterface $form_state) {
- parent::validate($form, $form_state);
+ public function validateForm(array &$form, FormStateInterface $form_state) {
+ parent::validateForm($form, $form_state);
// Validate field cardinality.
if ($form_state->getValue('cardinality') === 'number' && !$form_state->getValue('cardinality_number')) {
diff --git a/core/modules/filter/src/FilterFormatFormBase.php b/core/modules/filter/src/FilterFormatFormBase.php
index cbc68d6..be5fc56 100644
--- a/core/modules/filter/src/FilterFormatFormBase.php
+++ b/core/modules/filter/src/FilterFormatFormBase.php
@@ -204,8 +204,8 @@ public function exists($format_id) {
/**
* {@inheritdoc}
*/
- public function validate(array $form, FormStateInterface $form_state) {
- parent::validate($form, $form_state);
+ public function validateForm(array &$form, FormStateInterface $form_state) {
+ parent::validateForm($form, $form_state);
// @todo Move trimming upstream.
$format_format = trim($form_state->getValue('format'));
diff --git a/core/modules/forum/src/Form/Overview.php b/core/modules/forum/src/Form/Overview.php
index 24f5142..dae7fb5 100644
--- a/core/modules/forum/src/Form/Overview.php
+++ b/core/modules/forum/src/Form/Overview.php
@@ -86,9 +86,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
// Remove the alphabetical reset.
unset($form['actions']['reset_alphabetical']);
- // The form needs to have submit and validate handlers set explicitly.
// Use the existing taxonomy overview submit handler.
- $form['#submit'] = array('::submitForm');
$form['terms']['#empty'] = $this->t('No containers or forums available. Add container or Add forum.', array(
'@container' => $this->url('forum.add_container'),
'@forum' => $this->url('forum.add_forum')
diff --git a/core/modules/node/src/NodeTypeForm.php b/core/modules/node/src/NodeTypeForm.php
index 6dfc669..ff757f9 100644
--- a/core/modules/node/src/NodeTypeForm.php
+++ b/core/modules/node/src/NodeTypeForm.php
@@ -204,8 +204,8 @@ protected function actions(array $form, FormStateInterface $form_state) {
/**
* {@inheritdoc}
*/
- public function validate(array $form, FormStateInterface $form_state) {
- parent::validate($form, $form_state);
+ public function validateForm(array &$form, FormStateInterface $form_state) {
+ parent::validateForm($form, $form_state);
$id = trim($form_state->getValue('type'));
// '0' is invalid, since elsewhere we check it using empty().
diff --git a/core/modules/responsive_image/src/ResponsiveImageStyleForm.php b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php
index 365f7a5..171450b 100644
--- a/core/modules/responsive_image/src/ResponsiveImageStyleForm.php
+++ b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php
@@ -133,7 +133,8 @@ public function form(array $form, FormStateInterface $form_state) {
/**
* {@inheritdoc}
*/
- public function validate(array $form, FormStateInterface $form_state) {
+ public function validateForm(array &$form, FormStateInterface $form_state) {
+ parent::validateForm($form, $form_state);
// Only validate on edit.
if ($form_state->hasValue('keyed_styles')) {
// Check if another breakpoint group is selected.
diff --git a/core/modules/search/src/Form/SearchPageFormBase.php b/core/modules/search/src/Form/SearchPageFormBase.php
index 95afb4b..c41fd5b 100644
--- a/core/modules/search/src/Form/SearchPageFormBase.php
+++ b/core/modules/search/src/Form/SearchPageFormBase.php
@@ -144,8 +144,8 @@ public function exists($id) {
/**
* {@inheritdoc}
*/
- public function validate(array $form, FormStateInterface $form_state) {
- parent::validate($form, $form_state);
+ public function validateForm(array &$form, FormStateInterface $form_state) {
+ parent::validateForm($form, $form_state);
// Ensure each path is unique.
$path = $this->entityQuery->get('search_page')
diff --git a/core/modules/system/src/Form/DateFormatFormBase.php b/core/modules/system/src/Form/DateFormatFormBase.php
index c843ba2..fa1ac33 100644
--- a/core/modules/system/src/Form/DateFormatFormBase.php
+++ b/core/modules/system/src/Form/DateFormatFormBase.php
@@ -155,8 +155,8 @@ public function form(array $form, FormStateInterface $form_state) {
/**
* {@inheritdoc}
*/
- public function validate(array $form, FormStateInterface $form_state) {
- parent::validate($form, $form_state);
+ public function validateForm(array &$form, FormStateInterface $form_state) {
+ parent::validateForm($form, $form_state);
// The machine name field should already check to see if the requested
// machine name is available. Regardless of machine_name or human readable
diff --git a/core/modules/taxonomy/src/TermForm.php b/core/modules/taxonomy/src/TermForm.php
index daa2868..e168987 100644
--- a/core/modules/taxonomy/src/TermForm.php
+++ b/core/modules/taxonomy/src/TermForm.php
@@ -94,8 +94,8 @@ public function form(array $form, FormStateInterface $form_state) {
/**
* {@inheritdoc}
*/
- public function validate(array $form, FormStateInterface $form_state) {
- parent::validate($form, $form_state);
+ public function validateForm(array &$form, FormStateInterface $form_state) {
+ parent::validateForm($form, $form_state);
// Ensure numeric values.
if ($form_state->hasValue('weight') && !is_numeric($form_state->getValue('weight'))) {
diff --git a/core/modules/user/src/AccountForm.php b/core/modules/user/src/AccountForm.php
index 16ab69f..f8f94a4 100644
--- a/core/modules/user/src/AccountForm.php
+++ b/core/modules/user/src/AccountForm.php
@@ -354,9 +354,9 @@ public function buildEntity(array $form, FormStateInterface $form_state) {
/**
* {@inheritdoc}
*/
- public function validate(array $form, FormStateInterface $form_state) {
+ public function validateForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\user\UserInterface $account */
- $account = parent::validate($form, $form_state);
+ $account = parent::validateForm($form, $form_state);
// Skip the protected user field constraint if the user came from the
// password recovery page.
diff --git a/core/modules/views_ui/src/ViewAddForm.php b/core/modules/views_ui/src/ViewAddForm.php
index 9750094..0b41235 100644
--- a/core/modules/views_ui/src/ViewAddForm.php
+++ b/core/modules/views_ui/src/ViewAddForm.php
@@ -162,7 +162,7 @@ protected function actions(array $form, FormStateInterface $form_state) {
/**
* {@inheritdoc}
*/
- public function validate(array $form, FormStateInterface $form_state) {
+ public function validateForm(array &$form, FormStateInterface $form_state) {
$wizard_type = $form_state->getValue(array('show', 'wizard_key'));
$wizard_instance = $this->wizardManager->createInstance($wizard_type);
$form_state->set('wizard', $wizard_instance->getPluginDefinition());
diff --git a/core/modules/views_ui/src/ViewDuplicateForm.php b/core/modules/views_ui/src/ViewDuplicateForm.php
index 36f1a7f..ccc1a49 100644
--- a/core/modules/views_ui/src/ViewDuplicateForm.php
+++ b/core/modules/views_ui/src/ViewDuplicateForm.php
@@ -58,7 +58,6 @@ protected function actions(array $form, FormStateInterface $form_state) {
$actions['submit'] = array(
'#type' => 'submit',
'#value' => $this->t('Duplicate'),
- '#submit' => array('::submitForm'),
);
return $actions;
}
diff --git a/core/modules/views_ui/src/ViewEditForm.php b/core/modules/views_ui/src/ViewEditForm.php
index 2fc7fc4..672c5f1 100644
--- a/core/modules/views_ui/src/ViewEditForm.php
+++ b/core/modules/views_ui/src/ViewEditForm.php
@@ -258,8 +258,8 @@ protected function actions(array $form, FormStateInterface $form_state) {
/**
* {@inheritdoc}
*/
- public function validate(array $form, FormStateInterface $form_state) {
- parent::validate($form, $form_state);
+ public function validateForm(array &$form, FormStateInterface $form_state) {
+ parent::validateForm($form, $form_state);
$view = $this->entity;
if ($view->isLocked()) {