diff --git a/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php b/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php index 887fcae3676..a2874ce346b 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php @@ -121,7 +121,7 @@ abstract class ContentEntityConfirmFormBase extends ContentEntityForm implements /** * {@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 37406004883..81da6452d3d 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityForm.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityForm.php @@ -74,7 +74,7 @@ class ContentEntityForm extends EntityForm implements ContentEntityFormInterface * 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 fb015c767d1..60834c10c5a 100644 --- a/core/lib/Drupal/Core/Entity/EntityForm.php +++ b/core/lib/Drupal/Core/Entity/EntityForm.php @@ -247,7 +247,7 @@ class EntityForm extends FormBase implements EntityFormInterface { /** * {@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 29b248b0f23..d37f56c2cb0 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityFormInterface.php @@ -105,7 +105,7 @@ interface EntityFormInterface extends BaseFormIdInterface { * @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 96bb63d0636..864a067f442 100644 --- a/core/modules/action/src/ActionFormBase.php +++ b/core/modules/action/src/ActionFormBase.php @@ -123,7 +123,7 @@ abstract class ActionFormBase extends EntityForm { /** * {@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 08d7508086c..5746e31357a 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -273,7 +273,7 @@ class BlockForm extends EntityForm { /** * {@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 379e5763560..857776b3351 100644 --- a/core/modules/block_content/src/BlockContentForm.php +++ b/core/modules/block_content/src/BlockContentForm.php @@ -223,7 +223,7 @@ class BlockContentForm extends ContentEntityForm { /** * {@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 10c2152d34a..7a8cf505207 100644 --- a/core/modules/comment/src/CommentForm.php +++ b/core/modules/comment/src/CommentForm.php @@ -314,7 +314,7 @@ class CommentForm extends ContentEntityForm { /** * {@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 3300c593b69..6b80e0e02c1 100644 --- a/core/modules/contact/src/ContactFormEditForm.php +++ b/core/modules/contact/src/ContactFormEditForm.php @@ -112,7 +112,7 @@ class ContactFormEditForm extends EntityForm implements ContainerInjectionInterf /** * {@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 78de6ddc596..aeeb2cc1c27 100644 --- a/core/modules/contact/src/MessageForm.php +++ b/core/modules/contact/src/MessageForm.php @@ -187,7 +187,7 @@ class MessageForm extends ContentEntityForm { /** * {@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 d6d801b7551..4c83b504e73 100644 --- a/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php +++ b/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php @@ -38,7 +38,7 @@ class EntityDisplayModeAddForm extends EntityDisplayModeFormBase { /** * {@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 8a3cd54e0a2..27075d3ecd6 100644 --- a/core/modules/field_ui/src/Form/FieldConfigEditForm.php +++ b/core/modules/field_ui/src/Form/FieldConfigEditForm.php @@ -150,7 +150,7 @@ class FieldConfigEditForm extends EntityForm { /** * {@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 58c4ea9030d..f49e7476cbd 100644 --- a/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php +++ b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php @@ -146,7 +146,7 @@ class FieldStorageConfigEditForm extends EntityForm { /** * {@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 cbc68d61a1e..fb82b3bd3ad 100644 --- a/core/modules/filter/src/FilterFormatFormBase.php +++ b/core/modules/filter/src/FilterFormatFormBase.php @@ -204,7 +204,7 @@ abstract class FilterFormatFormBase extends EntityForm { /** * {@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 44fccbfb242..5d34b1adaf3 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -286,7 +286,7 @@ class NodeForm extends ContentEntityForm { /** * {@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 6dfc669df7c..f7307d6b403 100644 --- a/core/modules/node/src/NodeTypeForm.php +++ b/core/modules/node/src/NodeTypeForm.php @@ -204,7 +204,7 @@ class NodeTypeForm extends EntityForm { /** * {@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 365f7a5241e..ec6992f294e 100644 --- a/core/modules/responsive_image/src/ResponsiveImageStyleForm.php +++ b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php @@ -133,7 +133,7 @@ class ResponsiveImageStyleForm extends EntityForm { /** * {@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 95afb4ba962..02e95ca339d 100644 --- a/core/modules/search/src/Form/SearchPageFormBase.php +++ b/core/modules/search/src/Form/SearchPageFormBase.php @@ -144,7 +144,7 @@ abstract class SearchPageFormBase extends EntityForm { /** * {@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 c843ba24210..bece2431f9b 100644 --- a/core/modules/system/src/Form/DateFormatFormBase.php +++ b/core/modules/system/src/Form/DateFormatFormBase.php @@ -155,7 +155,7 @@ abstract class DateFormatFormBase extends EntityForm { /** * {@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 daa2868c380..b7116cb4178 100644 --- a/core/modules/taxonomy/src/TermForm.php +++ b/core/modules/taxonomy/src/TermForm.php @@ -94,7 +94,7 @@ class TermForm extends ContentEntityForm { /** * {@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 16ab69f6f0f..81e2ee650eb 100644 --- a/core/modules/user/src/AccountForm.php +++ b/core/modules/user/src/AccountForm.php @@ -354,7 +354,7 @@ abstract class AccountForm extends ContentEntityForm { /** * {@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 9750094fc7f..91dcf50883a 100644 --- a/core/modules/views_ui/src/ViewAddForm.php +++ b/core/modules/views_ui/src/ViewAddForm.php @@ -162,7 +162,7 @@ class ViewAddForm extends ViewFormBase { /** * {@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 2fc7fc4f821..b27233bdc1e 100644 --- a/core/modules/views_ui/src/ViewEditForm.php +++ b/core/modules/views_ui/src/ViewEditForm.php @@ -258,7 +258,7 @@ class ViewEditForm extends ViewFormBase { /** * {@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 810bdd1d6de..7d34fc1b9de 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php @@ -9,6 +9,7 @@ namespace Drupal\Tests\Core\Entity; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Form\FormState; +use Drupal\Core\Form\FormStateInterface; use Drupal\Tests\UnitTestCase; /** @@ -123,4 +124,20 @@ class EntityFormTest extends UnitTestCase { $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); + } + }