diff --git a/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php b/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php index 887fcae3676ccdce8217e5398d8174e3c08565bd..a2874ce346bae3e6a7335f5039c4251a2f8d2aa4 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 374060048839ef8573c208bf8f0ceec263123f34..81da6452d3d5817569fbce4e39261e0345fa6eda 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityForm.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityForm.php @@ -74,7 +74,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) { $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 fb015c767d1b36fe4e3f00dd67d29282fe4a06c2..60834c10c5ae955ff7850b5c2f2d66731741f7fb 100644 --- a/core/lib/Drupal/Core/Entity/EntityForm.php +++ b/core/lib/Drupal/Core/Entity/EntityForm.php @@ -247,7 +247,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) { // @todo Remove this. // Execute legacy global validation handlers. $form_state->setValidateHandlers([]); diff --git a/core/lib/Drupal/Core/Entity/EntityFormInterface.php b/core/lib/Drupal/Core/Entity/EntityFormInterface.php index 29b248b0f23acb633c1b2c09769e53b5a65202df..d37f56c2cb0b046d557b47a854358b7a9d7db57f 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 96bb63d0636078eb66268f497d99ff8f00f6cbad..864a067f442ce9226a451eb27f28707ff0fdbd92 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 08d7508086cf59fcbaa970ff88dcc7c6325eb420..5746e31357ae2d2a8599208892f04817204b2518 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -273,7 +273,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 379e5763560e06728b2a03e446f2b43dd7cec7de..857776b3351fe27fa55613e5daf26be3c84fb176 100644 --- a/core/modules/block_content/src/BlockContentForm.php +++ b/core/modules/block_content/src/BlockContentForm.php @@ -223,7 +223,7 @@ public function save(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function validateForm(array &$form, FormStateInterface $form_state) { + public function validate(array &$form, FormStateInterface $form_state) { if ($this->entity->isNew()) { $exists = $this->blockContentStorage->loadByProperties(array('info' => $form_state->getValue(['info', 0, 'value']))); if (!empty($exists)) { diff --git a/core/modules/comment/src/CommentForm.php b/core/modules/comment/src/CommentForm.php index 10c2152d34a935bbfe5bed5c0fbb9541a996dfb1..7a8cf505207db6af33af32d6815429a719531da8 100644 --- a/core/modules/comment/src/CommentForm.php +++ b/core/modules/comment/src/CommentForm.php @@ -314,7 +314,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 3300c593b69c5509675dea0a23e784357ffa5658..6b80e0e02c1273b498d28268caae4c795b7aaa89 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/contact/src/MessageForm.php b/core/modules/contact/src/MessageForm.php index 78de6ddc596a066992a3a92c326f152121e7d866..aeeb2cc1c2734ff89c67105b8d3999c1746ff644 100644 --- a/core/modules/contact/src/MessageForm.php +++ b/core/modules/contact/src/MessageForm.php @@ -187,7 +187,7 @@ public function preview(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); $message = $this->entity; diff --git a/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php b/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php index d6d801b7551c41bd59397fac5de391a6695933b5..4c83b504e736040d6b5ef68a0db25db375f6bd6b 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/field_ui/src/Form/FieldConfigEditForm.php b/core/modules/field_ui/src/Form/FieldConfigEditForm.php index 8a3cd54e0a294c40d55769cf1e30ee1aafb084b0..27075d3ecd6731616021edec423e210c2935cc3f 100644 --- a/core/modules/field_ui/src/Form/FieldConfigEditForm.php +++ b/core/modules/field_ui/src/Form/FieldConfigEditForm.php @@ -150,7 +150,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 (isset($form['default_value'])) { diff --git a/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php index 58c4ea9030d856b71874a3ad602e74f0802cba8c..f49e7476cbd2b98eabb1d5df175c55be6f017159 100644 --- a/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php +++ b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php @@ -146,7 +146,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); // Validate field cardinality. diff --git a/core/modules/filter/src/FilterFormatFormBase.php b/core/modules/filter/src/FilterFormatFormBase.php index cbc68d61a1e7c233cbdfb0cb8fa33d7154234adc..fb82b3bd3add5cae810ecfe1b150f9960fa7e10c 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 44fccbfb2424cb35867d141512c008e467e3ccb2..5d34b1adaf396dc968e4d8636abbdc7a0c5ff494 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -286,7 +286,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 6dfc669df7cb345cc59278aefa9e77f17190f8b0..f7307d6b403d8ab19f61932f63be8709cc1468d7 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 365f7a5241ef10af1b306c87784ca910492235f1..ec6992f294e335335897638fbb6ec101c61c4d7e 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 95afb4ba962d8686934edc724a68d8aa4ea557a3..02e95ca339d42315afe19f8e2fa5a57d6ccfa0e1 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 c843ba24210e8adfbbba6de2e116217fd6cde773..bece2431f9b7a2ad3535c015739c9de0416f59ff 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 daa2868c380820e9e3b2812e1a0178852081ff7d..b7116cb4178fc377faa298306d12aafb85c78d30 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 16ab69f6f0f4397683c4f585e0a8e5288ded8619..81e2ee650eb29fcb3eb9aaad144717e621a9c3b4 100644 --- a/core/modules/user/src/AccountForm.php +++ b/core/modules/user/src/AccountForm.php @@ -354,7 +354,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 9750094fc7ff00a6f2f1b94ab3a8a5ef14d66561..91dcf50883a272de922e14935d047b7afc14a732 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 2fc7fc4f821251eb551d47ec2361092076ab9926..b27233bdc1ed3bd1a4f1e96e47e6ef581ff3a2ef 100644 --- a/core/modules/views_ui/src/ViewEditForm.php +++ b/core/modules/views_ui/src/ViewEditForm.php @@ -258,7 +258,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; diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php index 810bdd1d6de840f57aba045371a244edac875a31..7d34fc1b9deb1e32c53c78f64803a22e5f5e4cda 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityForm; use Drupal\Core\Form\FormState; +use Drupal\Core\Form\FormStateInterface; use Drupal\Tests\UnitTestCase; /** @@ -123,4 +124,20 @@ public function testCopyFormValuesToEntity() { $this->assertNull($result->get('key_controlled_by_plugin_collection')); } + /** + * @covers ::validate + */ + public function testValidate() { + $form_object = $this->getMock('Drupal\Core\Entity\EntityFormInterface'); + $form_object->expects($this->once()) + ->method('validate') + ->willReturnCallback(function (array &$form, FormStateInterface $form_state) { + $form['foo'] = 'bar'; + }); + $form['baz'] = 'bim'; + $form_state = new FormState(); + $form_object->validate($form, $form_state); + $this->assertArrayHasKey('foo', $form); + } + }