From bd8f0f9b711a2202fdcb96d38eb67cf3cf55bfca Mon Sep 17 00:00:00 2001 From: catch Date: Mon, 18 Feb 2013 17:30:09 +0000 Subject: [PATCH] Issue #1913084 by tim.plunkett: Introduce a Form interface for building, validating, and submitting forms. --- core/includes/form.inc | 6 +++--- core/lib/Drupal/Core/Form/FormInterface.php | 6 +++--- .../lib/Drupal/block/BlockListController.php | 12 ++++++------ .../lib/Drupal/field_ui/DisplayOverview.php | 8 ++++---- .../lib/Drupal/field_ui/FieldOverview.php | 14 +++++++------- .../lib/Drupal/field_ui/OverviewBase.php | 8 ++++---- .../system/Tests/Form/FormObjectTest.php | 6 +++--- core/modules/system/system.module | 2 +- .../lib/Drupal/form_test/FormTestObject.php | 18 +++++++++--------- 9 files changed, 40 insertions(+), 40 deletions(-) diff --git a/core/includes/form.inc b/core/includes/form.inc index 4cdd101ccdc..bba00006b58 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -768,7 +768,7 @@ function drupal_retrieve_form($form_id, &$form_state) { $callback = $form_state['build_info']['callback']; } elseif (!empty($form_state['build_info']['callback_object'])) { - $callback = array($form_state['build_info']['callback_object'], 'build'); + $callback = array($form_state['build_info']['callback_object'], 'buildForm'); } // We first check to see if there is a valid form builder callback defined. @@ -1078,7 +1078,7 @@ function drupal_prepare_form($form_id, &$form, &$form_state) { // Ensure that modules can rely on #validate being set. $form['#validate'] = array(); if (isset($form_state['build_info']['callback_object'])) { - $form['#validate'][] = array($form_state['build_info']['callback_object'], 'validate'); + $form['#validate'][] = array($form_state['build_info']['callback_object'], 'validateForm'); } // Check for a handler specific to $form_id. elseif (function_exists($form_id . '_validate')) { @@ -1095,7 +1095,7 @@ function drupal_prepare_form($form_id, &$form, &$form_state) { // Ensure that modules can rely on #submit being set. $form['#submit'] = array(); if (isset($form_state['build_info']['callback_object'])) { - $form['#submit'][] = array($form_state['build_info']['callback_object'], 'submit'); + $form['#submit'][] = array($form_state['build_info']['callback_object'], 'submitForm'); } // Check for a handler specific to $form_id. elseif (function_exists($form_id . '_submit')) { diff --git a/core/lib/Drupal/Core/Form/FormInterface.php b/core/lib/Drupal/Core/Form/FormInterface.php index 2d8864ef4a9..17d721a2d0a 100644 --- a/core/lib/Drupal/Core/Form/FormInterface.php +++ b/core/lib/Drupal/Core/Form/FormInterface.php @@ -31,7 +31,7 @@ interface FormInterface { * @return array * The form structure. */ - public function build(array $form, array &$form_state); + public function buildForm(array $form, array &$form_state); /** * Form validation handler. @@ -41,7 +41,7 @@ interface FormInterface { * @param array $form_state * An associative array containing the current state of the form. */ - public function validate(array &$form, array &$form_state); + public function validateForm(array &$form, array &$form_state); /** * Form submission handler. @@ -51,6 +51,6 @@ interface FormInterface { * @param array $form_state * An associative array containing the current state of the form. */ - public function submit(array &$form, array &$form_state); + public function submitForm(array &$form, array &$form_state); } diff --git a/core/modules/block/lib/Drupal/block/BlockListController.php b/core/modules/block/lib/Drupal/block/BlockListController.php index bde1ce77582..e8f035c182c 100644 --- a/core/modules/block/lib/Drupal/block/BlockListController.php +++ b/core/modules/block/lib/Drupal/block/BlockListController.php @@ -100,11 +100,11 @@ class BlockListController extends ConfigEntityListController implements FormInte } /** - * Implements \Drupal\Core\Form\FormInterface::build(). + * Implements \Drupal\Core\Form\FormInterface::buildForm(). * * Form constructor for the main block administration form. */ - public function build(array $form, array &$form_state) { + public function buildForm(array $form, array &$form_state) { $entities = $this->load(); $form['#attached']['css'][] = drupal_get_path('module', 'block') . '/block.admin.css'; $form['#attached']['library'][] = array('system', 'drupal.tableheader'); @@ -190,18 +190,18 @@ class BlockListController extends ConfigEntityListController implements FormInte } /** - * Implements \Drupal\Core\Form\FormInterface::validate(). + * Implements \Drupal\Core\Form\FormInterface::validateForm(). */ - public function validate(array &$form, array &$form_state) { + public function validateForm(array &$form, array &$form_state) { // No validation. } /** - * Implements \Drupal\Core\Form\FormInterface::submit(). + * Implements \Drupal\Core\Form\FormInterface::submitForm(). * * Form submission handler for the main block administration form. */ - public function submit(array &$form, array &$form_state) { + public function submitForm(array &$form, array &$form_state) { $entities = entity_load_multiple('block', array_keys($form_state['values']['blocks'])); foreach ($entities as $entity_id => $entity) { $entity->set('weight', $form_state['values']['blocks'][$entity_id]['weight']); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php index 12e6011f29a..7ee40f448a1 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php @@ -39,9 +39,9 @@ class DisplayOverview extends OverviewBase { } /** - * Implements \Drupal\Core\Form\FormInterface::build(). + * Implements \Drupal\Core\Form\FormInterface::buildForm(). */ - public function build(array $form, array &$form_state) { + public function buildForm(array $form, array &$form_state) { // Gather type information. $instances = field_info_instances($this->entity_type, $this->bundle); $field_types = field_info_field_types(); @@ -407,9 +407,9 @@ class DisplayOverview extends OverviewBase { } /** - * Overrides \Drupal\field_ui\OverviewBase::submit(). + * Overrides \Drupal\field_ui\OverviewBase::submitForm(). */ - public function submit(array &$form, array &$form_state) { + public function submitForm(array &$form, array &$form_state) { $form_values = $form_state['values']; $display = entity_get_display($this->entity_type, $this->bundle, $this->view_mode); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php index 136a95197a7..925caef5b40 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php @@ -50,9 +50,9 @@ class FieldOverview extends OverviewBase { } /** - * Implements \Drupal\Core\Form\FormInterface::build(). + * Implements \Drupal\Core\Form\FormInterface::buildForm(). */ - public function build(array $form, array &$form_state) { + public function buildForm(array $form, array &$form_state) { // When displaying the form, make sure the list of fields is up-to-date. if (empty($form_state['post'])) { field_info_cache_clear(); @@ -420,9 +420,9 @@ class FieldOverview extends OverviewBase { } /** - * Overrides \Drupal\field_ui\OverviewBase::validate(). + * Implements \Drupal\Core\Form\FormInterface::validateForm(). */ - public function validate(array &$form, array &$form_state) { + public function validateForm(array &$form, array &$form_state) { $this->validateAddNew($form, $form_state); $this->validateAddExisting($form, $form_state); } @@ -435,7 +435,7 @@ class FieldOverview extends OverviewBase { * @param array $form_state * A reference to a keyed array containing the current state of the form. * - * @see Drupal\field_ui\FieldOverview::validate() + * @see Drupal\field_ui\FieldOverview::validateForm() */ protected function validateAddNew(array $form, array &$form_state) { $field = $form_state['values']['fields']['_add_new_field']; @@ -524,9 +524,9 @@ class FieldOverview extends OverviewBase { } /** - * Overrides \Drupal\field_ui\OverviewBase::submit(). + * Overrides \Drupal\field_ui\OverviewBase::submitForm(). */ - public function submit(array &$form, array &$form_state) { + public function submitForm(array &$form, array &$form_state) { $form_values = $form_state['values']['fields']; $bundle_settings = field_bundle_settings($this->entity_type, $this->bundle); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php b/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php index 9a37e679fef..5a76dc19980 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php @@ -61,15 +61,15 @@ abstract class OverviewBase implements FormInterface { } /** - * Implements \Drupal\Core\Form\FormInterface::validate(). + * Implements \Drupal\Core\Form\FormInterface::validateForm(). */ - public function validate(array &$form, array &$form_state) { + public function validateForm(array &$form, array &$form_state) { } /** - * Implements \Drupal\Core\Form\FormInterface::submit(). + * Implements \Drupal\Core\Form\FormInterface::submitForm(). */ - public function submit(array &$form, array &$form_state) { + public function submitForm(array &$form, array &$form_state) { } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/FormObjectTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/FormObjectTest.php index 9aee405ead4..c35a443a50a 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Form/FormObjectTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Form/FormObjectTest.php @@ -34,12 +34,12 @@ class FormObjectTest extends WebTestBase { */ function testObjectFormCallback() { $this->drupalGet('form-test/object-builder'); - $this->assertText('The FormTestObject::build() method was used for this form.'); + $this->assertText('The FormTestObject::buildForm() method was used for this form.'); $elements = $this->xpath('//form[@id="form-test-form-test-object"]'); $this->assertTrue(!empty($elements), 'The correct form ID was used.'); $this->drupalPost('form-test/object-builder', NULL, t('Save')); - $this->assertText('The FormTestObject::validate() method was used for this form.'); - $this->assertText('The FormTestObject::submit() method was used for this form.'); + $this->assertText('The FormTestObject::validateForm() method was used for this form.'); + $this->assertText('The FormTestObject::submitForm() method was used for this form.'); } } diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 83d1746aa74..1d7671b095d 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -3283,7 +3283,7 @@ function system_config_form($form, &$form_state) { if (!isset($form['#submit'])) { $form['#submit'] = array(); if (isset($form_state['build_info']['callback_object'])) { - $form['#submit'][] = array($form_state['build_info']['callback_object'], 'submit'); + $form['#submit'][] = array($form_state['build_info']['callback_object'], 'submitForm'); } elseif (function_exists($form_state['build_info']['form_id'] . '_submit')) { $form['#submit'][] = $form_state['build_info']['form_id'] . '_submit'; diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php index f3b0cf32898..f08d88e6a61 100644 --- a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php @@ -22,10 +22,10 @@ class FormTestObject implements FormInterface { } /** - * Implements \Drupal\Core\Form\FormInterface::build(). + * Implements \Drupal\Core\Form\FormInterface::buildForm(). */ - public function build(array $form, array &$form_state) { - $form['element'] = array('#markup' => 'The FormTestObject::build() method was used for this form.'); + public function buildForm(array $form, array &$form_state) { + $form['element'] = array('#markup' => 'The FormTestObject::buildForm() method was used for this form.'); $form['actions']['#type'] = 'actions'; $form['actions']['submit'] = array( @@ -36,17 +36,17 @@ class FormTestObject implements FormInterface { } /** - * Implements \Drupal\Core\Form\FormInterface::validate(). + * Implements \Drupal\Core\Form\FormInterface::validateForm(). */ - public function validate(array &$form, array &$form_state) { - drupal_set_message(t('The FormTestObject::validate() method was used for this form.')); + public function validateForm(array &$form, array &$form_state) { + drupal_set_message(t('The FormTestObject::validateForm() method was used for this form.')); } /** - * Implements \Drupal\Core\Form\FormInterface::submit(). + * Implements \Drupal\Core\Form\FormInterface::submitForm(). */ - public function submit(array &$form, array &$form_state) { - drupal_set_message(t('The FormTestObject::submit() method was used for this form.')); + public function submitForm(array &$form, array &$form_state) { + drupal_set_message(t('The FormTestObject::submitForm() method was used for this form.')); } }