From 74804f701a2331b90efb886a1be0fe96a0315232 Mon Sep 17 00:00:00 2001 From: webchick Date: Wed, 27 Feb 2013 17:17:09 -0500 Subject: [PATCH] Issue #1921996 by damiankloip, tim.plunkett, larowlan: Convert system_config_form() to implement FormInterface as a base class. --- .../Drupal/system/SystemConfigFormBase.php | 47 +++++++++++++++++++ .../Tests/Form/SystemConfigFormTest.php | 44 +++++++++++++++++ .../tests/modules/form_test/form_test.module | 14 ++++++ .../form_test/SystemConfigFormTestForm.php | 24 ++++++++++ .../views_ui/Form/AdvancedSettingsForm.php | 4 +- .../views_ui/Form/BasicSettingsForm.php | 4 +- .../Drupal/views_ui/Form/SettingsFormBase.php | 10 +--- 7 files changed, 137 insertions(+), 10 deletions(-) create mode 100644 core/modules/system/lib/Drupal/system/SystemConfigFormBase.php create mode 100644 core/modules/system/lib/Drupal/system/Tests/Form/SystemConfigFormTest.php create mode 100644 core/modules/system/tests/modules/form_test/lib/Drupal/form_test/SystemConfigFormTestForm.php diff --git a/core/modules/system/lib/Drupal/system/SystemConfigFormBase.php b/core/modules/system/lib/Drupal/system/SystemConfigFormBase.php new file mode 100644 index 00000000000..b415a707167 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/SystemConfigFormBase.php @@ -0,0 +1,47 @@ + 'submit', + '#value' => t('Save configuration'), + '#button_type' => 'primary', + ); + + // By default, render the form using theme_system_settings_form(). + $form['#theme'] = 'system_settings_form'; + + return $form; + } + + /** + * Implements \Drupal\Core\Form\FormInterface::validateForm(). + */ + public function validateForm(array &$form, array &$form_state) { + } + + /** + * Implements \Drupal\Core\Form\FormInterface::submitForm(). + */ + public function submitForm(array &$form, array &$form_state) { + drupal_set_message(t('The configuration options have been saved.')); + } + +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/SystemConfigFormTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/SystemConfigFormTest.php new file mode 100644 index 00000000000..724544890cf --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Form/SystemConfigFormTest.php @@ -0,0 +1,44 @@ + 'SystemConfigmForm tests', + 'description' => 'Tests the SystemConfigFormBase class.', + 'group' => 'Form API', + ); + } + + /** + * Tests the SystemConfigFormBase class. + */ + function testSystemConfigForm() { + $this->drupalGet('form-test/system-config-form'); + $element = $this->xpath('//div[@id = :id]/input[contains(@class, :class)]', array(':id' => 'edit-actions', ':class' => 'button-primary')); + $this->assertTrue($element, 'The primary action submit button was found.'); + $this->drupalPost(NULL, array(), t('Save configuration')); + $this->assertText(t('The configuration options have been saved.')); + } + +} diff --git a/core/modules/system/tests/modules/form_test/form_test.module b/core/modules/system/tests/modules/form_test/form_test.module index f85fd6df8fe..fe5d999dc6e 100644 --- a/core/modules/system/tests/modules/form_test/form_test.module +++ b/core/modules/system/tests/modules/form_test/form_test.module @@ -7,6 +7,7 @@ use Drupal\form_test\Callbacks; use Drupal\form_test\FormTestObject; +use Drupal\form_test\SystemConfigFormTestForm; use Drupal\Core\Datetime\DrupalDateTime; /** @@ -33,6 +34,12 @@ function form_test_menu() { 'access callback' => TRUE, 'type' => MENU_CALLBACK, ); + $items['form-test/system-config-form'] = array( + 'title' => 'Form object builder test', + 'page callback' => 'form_test_system_config_form', + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); $items['form-test/validate-required'] = array( 'title' => 'Form #required validation', 'page callback' => 'drupal_get_form', @@ -376,6 +383,13 @@ function form_test_object_builder() { return drupal_get_form(new FormTestObject()); } +/** + * Page callback: Displays a form built from SystemConfigForm. + */ +function form_test_system_config_form() { + return drupal_get_form(new SystemConfigFormTestForm()); +} + /** * Form submit handler to return form values as JSON. */ diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/SystemConfigFormTestForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/SystemConfigFormTestForm.php new file mode 100644 index 00000000000..26c1c0e464b --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/SystemConfigFormTestForm.php @@ -0,0 +1,24 @@ + 'details', '#title' => t('Caching'), @@ -75,7 +77,7 @@ class AdvancedSettingsForm extends SettingsFormBase { ); } - return system_config_form($form, $form_state); + return $form; } /** diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/BasicSettingsForm.php b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/BasicSettingsForm.php index 8617ebc04a2..082eaa33d82 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/BasicSettingsForm.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/BasicSettingsForm.php @@ -23,6 +23,8 @@ class BasicSettingsForm extends SettingsFormBase { * Implements \Drupal\Core\Form\FormInterface::buildForm(). */ public function buildForm(array $form, array &$form_state) { + $form = parent::buildForm($form, $form_state); + $options = array(); foreach (list_themes() as $name => $theme) { if ($theme->status) { @@ -115,7 +117,7 @@ class BasicSettingsForm extends SettingsFormBase { '#default_value' => $this->config->get('ui.show.additional_queries'), ); - return system_config_form($form, $form_state); + return $form; } /** diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/SettingsFormBase.php b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/SettingsFormBase.php index 173d5ecb9b8..fba4fa12e30 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/SettingsFormBase.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/SettingsFormBase.php @@ -7,13 +7,13 @@ namespace Drupal\views_ui\Form; -use Drupal\Core\Form\FormInterface; use Drupal\Core\Config\ConfigFactory; +use Drupal\system\SystemConfigFormBase; /** * Form builder for the advanced admin settings page. */ -abstract class SettingsFormBase implements FormInterface { +abstract class SettingsFormBase extends SystemConfigFormBase { /** * Stores the views configuration. @@ -42,10 +42,4 @@ abstract class SettingsFormBase implements FormInterface { return drupal_get_form($this); } - /** - * Implements \Drupal\Core\Form\FormInterface::validateForm(). - */ - public function validateForm(array &$form, array &$form_state) { - } - }