Issue #1921996 by damiankloip, tim.plunkett, larowlan: Convert system_config_form() to implement FormInterface as a base class.
parent
f7612eab1b
commit
74804f701a
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\system\SystemConfigFormBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\system;
|
||||
|
||||
use Drupal\Core\Form\FormInterface;
|
||||
|
||||
/**
|
||||
* Base class for implementing system configuration forms.
|
||||
*/
|
||||
abstract class SystemConfigFormBase implements FormInterface {
|
||||
|
||||
/**
|
||||
* Implements \Drupal\Core\Form\FormInterface::buildForm().
|
||||
*/
|
||||
public function buildForm(array $form, array &$form_state) {
|
||||
$form['actions']['#type'] = 'actions';
|
||||
$form['actions']['submit'] = array(
|
||||
'#type' => '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.'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\system\Tests\Form\SystemConfigFormTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\system\Tests\Form;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\form_test\SystemConfigFormTestForm;
|
||||
|
||||
/**
|
||||
* Tests the SystemConfigFormBase class.
|
||||
*/
|
||||
class SystemConfigFormTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('form_test');
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => '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.'));
|
||||
}
|
||||
|
||||
}
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\form_test\SystemConfigFormTestForm.
|
||||
*/
|
||||
|
||||
namespace Drupal\form_test;
|
||||
|
||||
use Drupal\system\SystemConfigFormBase;
|
||||
|
||||
/**
|
||||
* Tests the SystemConfigFormBase class.
|
||||
*/
|
||||
class SystemConfigFormTestForm extends SystemConfigFormBase {
|
||||
|
||||
/**
|
||||
* Implements \Drupal\Core\Form\FormInterface::getFormID().
|
||||
*/
|
||||
public function getFormID() {
|
||||
return 'form_test_system_config_test_form';
|
||||
}
|
||||
|
||||
}
|
|
@ -23,6 +23,8 @@ class AdvancedSettingsForm extends SettingsFormBase {
|
|||
* Implements \Drupal\Core\Form\FormInterface::buildForm().
|
||||
*/
|
||||
public function buildForm(array $form, array &$form_state) {
|
||||
$form = parent::buildForm($form, $form_state);
|
||||
|
||||
$form['cache'] = array(
|
||||
'#type' => 'details',
|
||||
'#title' => t('Caching'),
|
||||
|
@ -75,7 +77,7 @@ class AdvancedSettingsForm extends SettingsFormBase {
|
|||
);
|
||||
}
|
||||
|
||||
return system_config_form($form, $form_state);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue