From 0670a5fe01e5bfdc8d191add00effdba5263184e Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 15 Apr 2015 20:13:21 +0200 Subject: [PATCH] Revert "Issue #2459753 by tim.plunkett: EntityForm::validate() should be able to modify the form structure" This reverts commit d4d83576d2efb78fbef7aef22ef0b1d33dce25fd. --- .../Entity/ContentEntityConfirmFormBase.php | 2 +- .../Drupal/Core/Entity/ContentEntityForm.php | 2 +- core/lib/Drupal/Core/Entity/EntityForm.php | 2 +- .../Drupal/Core/Entity/EntityFormInterface.php | 2 +- core/modules/action/src/ActionFormBase.php | 2 +- core/modules/block/src/BlockForm.php | 2 +- .../block_content/src/BlockContentForm.php | 2 +- core/modules/comment/src/CommentForm.php | 2 +- .../modules/contact/src/ContactFormEditForm.php | 2 +- .../src/Form/EntityDisplayModeAddForm.php | 2 +- .../modules/filter/src/FilterFormatFormBase.php | 2 +- core/modules/node/src/NodeForm.php | 2 +- core/modules/node/src/NodeTypeForm.php | 2 +- .../src/ResponsiveImageStyleForm.php | 2 +- .../search/src/Form/SearchPageFormBase.php | 2 +- .../system/src/Form/DateFormatFormBase.php | 2 +- core/modules/taxonomy/src/TermForm.php | 2 +- core/modules/user/src/AccountForm.php | 2 +- core/modules/views_ui/src/ViewAddForm.php | 2 +- core/modules/views_ui/src/ViewEditForm.php | 2 +- .../Drupal/Tests/Core/Entity/EntityFormTest.php | 17 ----------------- 21 files changed, 20 insertions(+), 37 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php b/core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase.php index a2874ce346ba..887fcae3676c 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 81da6452d3d5..374060048839 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 60834c10c5ae..fb015c767d1b 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 d37f56c2cb0b..29b248b0f23a 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 864a067f442c..96bb63d06360 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 5746e31357ae..08d7508086cf 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 857776b3351f..379e5763560e 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 validate(array &$form, FormStateInterface $form_state) { + public function validateForm(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 7a8cf505207d..10c2152d34a9 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 6b80e0e02c12..3300c593b69c 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/field_ui/src/Form/EntityDisplayModeAddForm.php b/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php index 4c83b504e736..d6d801b7551c 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/filter/src/FilterFormatFormBase.php b/core/modules/filter/src/FilterFormatFormBase.php index fb82b3bd3add..cbc68d61a1e7 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 5d34b1adaf39..44fccbfb2424 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 f7307d6b403d..6dfc669df7cb 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 ec6992f294e3..365f7a5241ef 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 02e95ca339d4..95afb4ba962d 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 bece2431f9b7..c843ba24210e 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 b7116cb4178f..daa2868c3808 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 81e2ee650eb2..16ab69f6f0f4 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 91dcf50883a2..9750094fc7ff 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 b27233bdc1ed..2fc7fc4f8212 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 7d34fc1b9deb..810bdd1d6de8 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php @@ -9,7 +9,6 @@ namespace Drupal\Tests\Core\Entity; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Form\FormState; -use Drupal\Core\Form\FormStateInterface; use Drupal\Tests\UnitTestCase; /** @@ -124,20 +123,4 @@ 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); - } - }