diff --git a/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php b/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php index 887fcae..a2874ce 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php @@ -121,7 +121,7 @@ public function delete(array $form, FormStateInterface $form_state) {} /** * {@inheritdoc} */ - public function validate(array $form, FormStateInterface $form_state) { + public function validate(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. } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityForm.php b/core/lib/Drupal/Core/Entity/ContentEntityForm.php index 58b5ca4..b8808fb 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityForm.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityForm.php @@ -68,7 +68,7 @@ public function form(array $form, FormStateInterface $form_state) { * For more information about entity validation, see * https://www.drupal.org/node/2015613. */ - public function validate(array $form, FormStateInterface $form_state) { + public function validate(array &$form, FormStateInterface $form_state) { parent::validate($form, $form_state); $entity = $this->buildEntity($form, $form_state); $this->getFormDisplay($form_state)->validateFormValues($entity, $form, $form_state); diff --git a/core/lib/Drupal/Core/Entity/EntityForm.php b/core/lib/Drupal/Core/Entity/EntityForm.php index 921692a..30d8aa2 100644 --- a/core/lib/Drupal/Core/Entity/EntityForm.php +++ b/core/lib/Drupal/Core/Entity/EntityForm.php @@ -230,7 +230,7 @@ protected function actions(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function validate(array $form, FormStateInterface $form_state) { + public function validate(array &$form, FormStateInterface $form_state) { } /** diff --git a/core/lib/Drupal/Core/Entity/EntityFormInterface.php b/core/lib/Drupal/Core/Entity/EntityFormInterface.php index 29b248b..d37f56c 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityFormInterface.php @@ -105,7 +105,7 @@ public function buildEntity(array $form, FormStateInterface $form_state); * @return \Drupal\Core\Entity\ContentEntityTypeInterface * The built entity. */ - public function validate(array $form, FormStateInterface $form_state); + public function validate(array &$form, FormStateInterface $form_state); /** * Form submission handler for the 'save' action. diff --git a/core/modules/action/src/ActionFormBase.php b/core/modules/action/src/ActionFormBase.php index 96bb63d..864a067 100644 --- a/core/modules/action/src/ActionFormBase.php +++ b/core/modules/action/src/ActionFormBase.php @@ -123,7 +123,7 @@ protected function actions(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function validate(array $form, FormStateInterface $form_state) { + public function validate(array &$form, FormStateInterface $form_state) { parent::validate($form, $form_state); if ($this->plugin instanceof PluginFormInterface) { diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php index 3ff21f6..52dbe5d 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -272,7 +272,7 @@ protected function actions(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function validate(array $form, FormStateInterface $form_state) { + public function validate(array &$form, FormStateInterface $form_state) { parent::validate($form, $form_state); // The Block Entity form puts all block plugin form elements in the diff --git a/core/modules/block_content/src/BlockContentForm.php b/core/modules/block_content/src/BlockContentForm.php index 379e576..715409d 100644 --- a/core/modules/block_content/src/BlockContentForm.php +++ b/core/modules/block_content/src/BlockContentForm.php @@ -223,8 +223,9 @@ public function save(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function validateForm(array &$form, FormStateInterface $form_state) { - if ($this->entity->isNew()) { + public function validate(array &$form, FormStateInterface $form_state) { + $entity = parent::validate($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/comment/src/CommentForm.php b/core/modules/comment/src/CommentForm.php index 95629b2..b5a75ff 100644 --- a/core/modules/comment/src/CommentForm.php +++ b/core/modules/comment/src/CommentForm.php @@ -297,7 +297,7 @@ public function buildEntity(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function validate(array $form, FormStateInterface $form_state) { + public function validate(array &$form, FormStateInterface $form_state) { $comment = parent::validate($form, $form_state); // Customly trigger validation of manually added fields and add in diff --git a/core/modules/contact/src/ContactFormEditForm.php b/core/modules/contact/src/ContactFormEditForm.php index 3300c59..6b80e0e 100644 --- a/core/modules/contact/src/ContactFormEditForm.php +++ b/core/modules/contact/src/ContactFormEditForm.php @@ -112,7 +112,7 @@ public function form(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function validate(array $form, FormStateInterface $form_state) { + public function validate(array &$form, FormStateInterface $form_state) { parent::validate($form, $form_state); // Validate and each email recipient. diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module index 2c53d24..6350ce6 100644 --- a/core/modules/editor/editor.module +++ b/core/modules/editor/editor.module @@ -160,7 +160,7 @@ function editor_form_filter_format_form_alter(&$form, FormStateInterface $form_s $form['actions']['submit']['#submit'][] = array($plugin, 'settingsFormSubmit'); } - $form['#validate'][] = 'editor_form_filter_admin_format_validate'; + $form['actions']['submit']['#validate'][] = 'editor_form_filter_admin_format_validate'; $form['actions']['submit']['#submit'][] = 'editor_form_filter_admin_format_submit'; } diff --git a/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php b/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php index d6d801b..4c83b50 100644 --- a/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php +++ b/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php @@ -38,7 +38,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t /** * {@inheritdoc} */ - public function validate(array $form, FormStateInterface $form_state) { + public function validate(array &$form, FormStateInterface $form_state) { parent::validate($form, $form_state); $form_state->setValueForElement($form['id'], $this->targetEntityTypeId . '.' . $form_state->getValue('id')); diff --git a/core/modules/filter/src/FilterFormatFormBase.php b/core/modules/filter/src/FilterFormatFormBase.php index c370279..11c4501 100644 --- a/core/modules/filter/src/FilterFormatFormBase.php +++ b/core/modules/filter/src/FilterFormatFormBase.php @@ -204,7 +204,7 @@ public function exists($format_id) { /** * {@inheritdoc} */ - public function validate(array $form, FormStateInterface $form_state) { + public function validate(array &$form, FormStateInterface $form_state) { parent::validate($form, $form_state); // @todo Move trimming upstream. diff --git a/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php index 92e7c0c..548bd5b 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -291,7 +291,7 @@ protected function actions(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function validate(array $form, FormStateInterface $form_state) { + public function validate(array &$form, FormStateInterface $form_state) { $node = parent::validate($form, $form_state); if ($node->id() && (node_last_changed($node->id(), $this->getFormLangcode($form_state)) > $node->getChangedTime())) { diff --git a/core/modules/node/src/NodeTypeForm.php b/core/modules/node/src/NodeTypeForm.php index b5c4674..d106dad 100644 --- a/core/modules/node/src/NodeTypeForm.php +++ b/core/modules/node/src/NodeTypeForm.php @@ -204,7 +204,7 @@ protected function actions(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function validate(array $form, FormStateInterface $form_state) { + public function validate(array &$form, FormStateInterface $form_state) { parent::validate($form, $form_state); $id = trim($form_state->getValue('type')); diff --git a/core/modules/responsive_image/src/ResponsiveImageStyleForm.php b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php index 365f7a5..ec6992f 100644 --- a/core/modules/responsive_image/src/ResponsiveImageStyleForm.php +++ b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php @@ -133,7 +133,7 @@ public function form(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function validate(array $form, FormStateInterface $form_state) { + public function validate(array &$form, FormStateInterface $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..02e95ca 100644 --- a/core/modules/search/src/Form/SearchPageFormBase.php +++ b/core/modules/search/src/Form/SearchPageFormBase.php @@ -144,7 +144,7 @@ public function exists($id) { /** * {@inheritdoc} */ - public function validate(array $form, FormStateInterface $form_state) { + public function validate(array &$form, FormStateInterface $form_state) { parent::validate($form, $form_state); // Ensure each path is unique. diff --git a/core/modules/system/src/Form/DateFormatFormBase.php b/core/modules/system/src/Form/DateFormatFormBase.php index c843ba2..bece243 100644 --- a/core/modules/system/src/Form/DateFormatFormBase.php +++ b/core/modules/system/src/Form/DateFormatFormBase.php @@ -155,7 +155,7 @@ public function form(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function validate(array $form, FormStateInterface $form_state) { + public function validate(array &$form, FormStateInterface $form_state) { parent::validate($form, $form_state); // The machine name field should already check to see if the requested diff --git a/core/modules/taxonomy/src/TermForm.php b/core/modules/taxonomy/src/TermForm.php index daa2868..b7116cb 100644 --- a/core/modules/taxonomy/src/TermForm.php +++ b/core/modules/taxonomy/src/TermForm.php @@ -94,7 +94,7 @@ public function form(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function validate(array $form, FormStateInterface $form_state) { + public function validate(array &$form, FormStateInterface $form_state) { parent::validate($form, $form_state); // Ensure numeric values. diff --git a/core/modules/user/src/AccountForm.php b/core/modules/user/src/AccountForm.php index 8c14682..540120c 100644 --- a/core/modules/user/src/AccountForm.php +++ b/core/modules/user/src/AccountForm.php @@ -40,6 +40,13 @@ protected $entityQuery; /** + * The entity being used by this form. + * + * @var \Drupal\user\UserInterface + */ + protected $entity; + + /** * Constructs a new EntityForm object. * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager @@ -70,7 +77,6 @@ public static function create(ContainerInterface $container) { * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { - /** @var \Drupal\user\UserInterface $account */ $account = $this->entity; $user = $this->currentUser(); $config = \Drupal::config('user.settings'); @@ -173,7 +179,6 @@ public function form(array $form, FormStateInterface $form_state) { ); $form_state->set('user', $account); - $form['#validate'][] = 'user_validate_current_pass'; } } elseif (!$config->get('verify_mail') || $admin) { @@ -333,6 +338,17 @@ public function alterPreferredLangcodeDescription(array $element) { } /** + * {@inheritdoc} + */ + protected function actions(array $form, FormStateInterface $form_state) { + $actions = parent::actions($form, $form_state); + if (!$this->entity->isAnonymous() && $this->currentUser()->id() == $this->entity->id()) { + $actions['submit']['#validate'][] = 'user_validate_current_pass'; + } + return $actions; + } + + /** * Synchronizes preferred language and entity language. * * @param string $entity_type_id @@ -383,7 +399,7 @@ public function buildEntity(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function validate(array $form, FormStateInterface $form_state) { + public function validate(array &$form, FormStateInterface $form_state) { /** @var \Drupal\user\UserInterface $account */ $account = parent::validate($form, $form_state); diff --git a/core/modules/views_ui/src/ViewAddForm.php b/core/modules/views_ui/src/ViewAddForm.php index 9750094..91dcf50 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 validate(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/ViewEditForm.php b/core/modules/views_ui/src/ViewEditForm.php index 1205f28..ca38ed0 100644 --- a/core/modules/views_ui/src/ViewEditForm.php +++ b/core/modules/views_ui/src/ViewEditForm.php @@ -246,7 +246,7 @@ protected function actions(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function validate(array $form, FormStateInterface $form_state) { + public function validate(array &$form, FormStateInterface $form_state) { parent::validate($form, $form_state); $view = $this->entity;