Commit f905406d authored by webchick's avatar webchick

Issue #2078867 by tim.plunkett, jackbravo, ianthomas_uk, InternetDevels,...

Issue #2078867 by tim.plunkett, jackbravo, ianthomas_uk, InternetDevels, piyuesh23, disasm, nano_monkey | vijaycs85: Convert _form_test_* functions to classes.
parent 8501b7f2
......@@ -384,166 +384,6 @@ function _form_test_tableselect_get_data() {
return array($header, $options);
}
/**
* Build a form to test the tableselect element.
*
* @param $form_state
* The form_state
* @param $element_properties
* An array of element properties for the tableselect element.
*
* @return
* A form with a tableselect element and a submit button.
*/
function _form_test_tableselect_form_builder($form, $form_state, $element_properties) {
list($header, $options) = _form_test_tableselect_get_data();
$form['tableselect'] = $element_properties;
$form['tableselect'] += array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#multiple' => FALSE,
'#empty' => t('Empty text.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
/**
* Test the tableselect #multiple = TRUE functionality.
*
* @deprecated Use \Drupal\form_test\testTableSelectCheckboxes()
*/
function _form_test_tableselect_multiple_true_form($form, $form_state) {
return _form_test_tableselect_form_builder($form, $form_state, array('#multiple' => TRUE));
}
/**
* Process the tableselect #multiple = TRUE submitted values.
*/
function _form_test_tableselect_multiple_true_form_submit($form, &$form_state) {
$selected = $form_state['values']['tableselect'];
foreach ($selected as $key => $value) {
drupal_set_message(t('Submitted: @key = @value', array('@key' => $key, '@value' => $value)));
}
}
/**
* Test the tableselect #multiple = FALSE functionality.
*
* @deprecated Use \Drupal\form_test\testTableSelectRadios()
*/
function _form_test_tableselect_multiple_false_form($form, $form_state) {
return _form_test_tableselect_form_builder($form, $form_state, array('#multiple' => FALSE));
}
/**
* Test the tableselect #colspan functionality.
*
* @deprecated Use \Drupal\form_test\testTableSelectColspan()
*/
function _form_test_tableselect_colspan_form($form, $form_state) {
list($header, $options) = _form_test_tableselect_get_data();
// Change the data so that the third column has colspan=2.
$header['three'] = array('data' => 'Three', 'colspan' => 2);
unset($header['four']);
// Set the each row so that column 3 is an array.
foreach ($options as $name => $row) {
$options[$name]['three'] = array($row['three'], $row['four']);
unset($options[$name]['four']);
}
// Combine cells in row 3.
$options['row3']['one'] = array('data' => $options['row3']['one'], 'colspan' => 2);
unset($options['row3']['two']);
$options['row3']['three'] = array('data' => $options['row3']['three'][0], 'colspan' => 2);
unset($options['row3']['four']);
return _form_test_tableselect_form_builder($form, $form_state, array('#header' => $header, '#options' => $options));
}
/**
* Process the tableselect #multiple = FALSE submitted values.
*/
function _form_test_tableselect_multiple_false_form_submit($form, &$form_state) {
drupal_set_message(t('Submitted: @value', array('@value' => $form_state['values']['tableselect'])));
}
/**
* Test functionality of the tableselect #empty property.
*
* @deprecated Use \Drupal\form_test\testTableSelectEmptyText()
*/
function _form_test_tableselect_empty_form($form, $form_state) {
return _form_test_tableselect_form_builder($form, $form_state, array('#options' => array()));
}
/**
* Test functionality of the tableselect #js_select property.
*
* @deprecated Use \Drupal\form_test\testTableSelectJS()
*/
function _form_test_tableselect_js_select_form($form, $form_state, $action) {
switch ($action) {
case 'multiple-true-default':
$options = array('#multiple' => TRUE);
break;
case 'multiple-false-default':
$options = array('#multiple' => FALSE);
break;
case 'multiple-true-no-advanced-select':
$options = array('#multiple' => TRUE, '#js_select' => FALSE);
break;
case 'multiple-false-advanced-select':
$options = array('#multiple' => FALSE, '#js_select' => TRUE);
break;
}
return _form_test_tableselect_form_builder($form, $form_state, $options);
}
/**
* Tests functionality of vertical tabs.
*
* @deprecated Use \Drupal\form_test\testVerticalTabs()
*/
function _form_test_vertical_tabs_form($form, &$form_state) {
$form['vertical_tabs'] = array(
'#type' => 'vertical_tabs',
);
$form['tab1'] = array(
'#type' => 'details',
'#title' => t('Tab 1'),
'#group' => 'vertical_tabs',
'#access' => user_access('access vertical_tab_test tabs'),
);
$form['tab1']['field1'] = array(
'#title' => t('Field 1'),
'#type' => 'textfield',
);
$form['tab2'] = array(
'#type' => 'details',
'#title' => t('Tab 2'),
'#group' => 'vertical_tabs',
'#access' => user_access('access vertical_tab_test tabs'),
);
$form['tab2']['field2'] = array(
'#title' => t('Field 2'),
'#type' => 'textfield',
);
return $form;
}
/**
* A multistep form for testing the form storage.
*
......@@ -799,77 +639,6 @@ function form_test_form_state_values_clean_advanced_form_submit($form, &$form_st
exit;
}
/**
* Build a form to test a checkbox.
*
* @deprecated Use \Drupal\form_test\testCheckbox()
*/
function _form_test_checkbox($form, &$form_state) {
$form['#submit'] = array('_form_test_submit_values_json');
// A required checkbox.
$form['required_checkbox'] = array(
'#type' => 'checkbox',
'#required' => TRUE,
'#title' => 'required_checkbox',
);
// A disabled checkbox should get its default value back.
$form['disabled_checkbox_on'] = array(
'#type' => 'checkbox',
'#disabled' => TRUE,
'#return_value' => 'disabled_checkbox_on',
'#default_value' => 'disabled_checkbox_on',
'#title' => 'disabled_checkbox_on',
);
$form['disabled_checkbox_off'] = array(
'#type' => 'checkbox',
'#disabled' => TRUE,
'#return_value' => 'disabled_checkbox_off',
'#default_value' => NULL,
'#title' => 'disabled_checkbox_off',
);
// A checkbox is active when #default_value == #return_value.
$form['checkbox_on'] = array(
'#type' => 'checkbox',
'#return_value' => 'checkbox_on',
'#default_value' => 'checkbox_on',
'#title' => 'checkbox_on',
);
// But inactive in any other case.
$form['checkbox_off'] = array(
'#type' => 'checkbox',
'#return_value' => 'checkbox_off',
'#default_value' => 'checkbox_on',
'#title' => 'checkbox_off',
);
// Checkboxes with a #return_value of '0' are supported.
$form['zero_checkbox_on'] = array(
'#type' => 'checkbox',
'#return_value' => '0',
'#default_value' => '0',
'#title' => 'zero_checkbox_on',
);
// In that case, passing a #default_value != '0' means that the checkbox is off.
$form['zero_checkbox_off'] = array(
'#type' => 'checkbox',
'#return_value' => '0',
'#default_value' => '1',
'#title' => 'zero_checkbox_off',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit')
);
return $form;
}
/**
* Builds a form to test #type 'select' validation.
*
......@@ -1578,31 +1347,6 @@ function _form_test_disabled_elements($form, &$form_state) {
return $form;
}
/**
* Build a form to test input forgery of enabled elements.
*
* @deprecated Use \Drupal\form_test\testInputForgery()
*/
function _form_test_input_forgery($form, &$form_state) {
$form['#submit'] = array('_form_test_submit_values_json');
// For testing that a user can't submit a value not matching one of the
// allowed options.
$form['checkboxes'] = array(
'#title' => t('Checkboxes'),
'#type' => 'checkboxes',
'#options' => array(
'one' => 'One',
'two' => 'Two',
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
/**
* Form builder for testing preservation of values during a rebuild.
*
......
......@@ -119,7 +119,7 @@ form_test.pattern:
form_test.tableselect_checkboxes:
path: '/form_test/tableselect/multiple-true'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testTableSelectCheckboxes'
_form: '\Drupal\form_test\Form\FormTestTableSelectMultipleTrueForm'
_title: 'Tableselect checkboxes test'
requirements:
_access: 'TRUE'
......@@ -127,7 +127,7 @@ form_test.tableselect_checkboxes:
form_test.tableselect_radios:
path: '/form_test/tableselect/multiple-false'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testTableSelectRadios'
_form: '\Drupal\form_test\Form\FormTestTableSelectMultipleFalseForm'
_title: 'Tableselect radio button test'
requirements:
_access: 'TRUE'
......@@ -135,7 +135,7 @@ form_test.tableselect_radios:
form_test.tableselect_colspan:
path: '/form_test/tableselect/colspan'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testTableSelectColspan'
_form: '\Drupal\form_test\Form\FormTestTableSelectColspanForm'
_title: 'Tableselect colspan test'
requirements:
_access: 'TRUE'
......@@ -143,7 +143,7 @@ form_test.tableselect_colspan:
form_test.tableselect_empty_text:
path: '/form_test/tableselect/empty-text'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testTableSelectEmptyText'
_form: '\Drupal\form_test\Form\FormTestTableSelectEmptyForm'
_title: 'Tableselect empty text test'
requirements:
_access: 'TRUE'
......@@ -151,7 +151,7 @@ form_test.tableselect_empty_text:
form_test.tableselect_js:
path: '/form_test/tableselect/advanced-select/{test_action}'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testTableSelectJS'
_form: '\Drupal\form_test\Form\FormTestTableSelectJsSelectForm'
_title: 'Tableselect js_select tests'
requirements:
_access: 'TRUE'
......@@ -159,7 +159,7 @@ form_test.tableselect_js:
form_test.vertical_tabs:
path: '/form_test/vertical-tabs'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testVerticalTabs'
_form: '\Drupal\form_test\Form\FormTestVerticalTabsForm'
_title: 'Vertical tabs tests'
requirements:
_access: 'TRUE'
......@@ -191,7 +191,7 @@ form_test.state_clean_advanced:
form_test.checkbox:
path: '/form-test/checkbox'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testCheckbox'
_form: '\Drupal\form_test\Form\FormTestCheckboxForm'
_title: 'Form test'
requirements:
_access: 'TRUE'
......@@ -304,7 +304,7 @@ form_test.disabled_elements:
form_test.input_forgery:
path: '/form-test/input-forgery'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testInputForgery'
_form: '\Drupal\form_test\Form\FormTestInputForgeryForm'
_title: 'Form test'
requirements:
_access: 'TRUE'
......
<?php
/**
* @file
* Contains \Drupal\form_test\Form\FormTestCheckboxForm.
*/
namespace Drupal\form_test\Form;
use Drupal\Core\Form\FormBase;
use Symfony\Component\HttpFoundation\JsonResponse;
class FormTestCheckboxForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return '_test_checkbox_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
// A required checkbox.
$form['required_checkbox'] = array(
'#type' => 'checkbox',
'#required' => TRUE,
'#title' => 'required_checkbox',
);
// A disabled checkbox should get its default value back.
$form['disabled_checkbox_on'] = array(
'#type' => 'checkbox',
'#disabled' => TRUE,
'#return_value' => 'disabled_checkbox_on',
'#default_value' => 'disabled_checkbox_on',
'#title' => 'disabled_checkbox_on',
);
$form['disabled_checkbox_off'] = array(
'#type' => 'checkbox',
'#disabled' => TRUE,
'#return_value' => 'disabled_checkbox_off',
'#default_value' => NULL,
'#title' => 'disabled_checkbox_off',
);
// A checkbox is active when #default_value == #return_value.
$form['checkbox_on'] = array(
'#type' => 'checkbox',
'#return_value' => 'checkbox_on',
'#default_value' => 'checkbox_on',
'#title' => 'checkbox_on',
);
// But inactive in any other case.
$form['checkbox_off'] = array(
'#type' => 'checkbox',
'#return_value' => 'checkbox_off',
'#default_value' => 'checkbox_on',
'#title' => 'checkbox_off',
);
// Checkboxes with a #return_value of '0' are supported.
$form['zero_checkbox_on'] = array(
'#type' => 'checkbox',
'#return_value' => '0',
'#default_value' => '0',
'#title' => 'zero_checkbox_on',
);
// In that case, passing a #default_value != '0'
// means that the checkbox is off.
$form['zero_checkbox_off'] = array(
'#type' => 'checkbox',
'#return_value' => '0',
'#default_value' => '1',
'#title' => 'zero_checkbox_off',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$response = new JsonResponse($form_state['values']);
// @todo remove once converted to new routing system.
$response->send();
exit;
}
}
......@@ -66,60 +66,6 @@ public function validatePattern() {
return \Drupal::formBuilder()->getForm('form_test_pattern_form');
}
/**
* Wraps _form_test_tableselect_multiple_true_form().
*
* @todo Remove _form_test_tableselect_multiple_true_form().
*/
public function testTableSelectCheckboxes() {
return \Drupal::formBuilder()->getForm('_form_test_tableselect_multiple_true_form');
}
/**
* Wraps _form_test_tableselect_multiple_false_form().
*
* @todo Remove _form_test_tableselect_multiple_false_form().
*/
public function testTableSelectRadios() {
return \Drupal::formBuilder()->getForm('_form_test_tableselect_multiple_false_form');
}
/**
* Wraps _form_test_tableselect_colspan_form().
*
* @todo Remove _form_test_tableselect_colspan_form().
*/
public function testTableSelectColspan() {
return \Drupal::formBuilder()->getForm('_form_test_tableselect_colspan_form');
}
/**
* Wraps _form_test_tableselect_empty_form().
*
* @todo Remove _form_test_tableselect_empty_form().
*/
public function testTableSelectEmptyText() {
return \Drupal::formBuilder()->getForm('_form_test_tableselect_empty_form');
}
/**
* Wraps _form_test_tableselect_js_select_form().
*
* @todo Remove _form_test_tableselect_js_select_form().
*/
public function testTableSelectJS($test_action) {
return \Drupal::formBuilder()->getForm('_form_test_tableselect_js_select_form', $test_action);
}
/**
* Wraps _form_test_vertical_tabs_form().
*
* @todo Remove _form_test_vertical_tabs_form().
*/
public function testVerticalTabs() {
return \Drupal::formBuilder()->getForm('_form_test_vertical_tabs_form');
}
/**
* Wraps form_test_storage_form().
*
......@@ -147,15 +93,6 @@ public function testFormStateCleanAdvanced() {
return \Drupal::formBuilder()->getForm('form_test_form_state_values_clean_advanced_form');
}
/**
* Wraps _form_test_checkbox().
*
* @todo Remove _form_test_checkbox().
*/
public function testCheckbox() {
return \Drupal::formBuilder()->getForm('_form_test_checkbox');
}
/**
* Wraps form_test_select().
*
......@@ -273,15 +210,6 @@ public function testDisabledElements() {
return \Drupal::formBuilder()->getForm('_form_test_disabled_elements');
}
/**
* Wraps _form_test_input_forgery().
*
* @todo Remove _form_test_input_forgery().
*/
public function testInputForgery() {
return \Drupal::formBuilder()->getForm('_form_test_input_forgery');
}
/**
* Wraps form_test_form_rebuild_preserve_values_form().
*
......
<?php
/**
* @file
* Contains Drupal/form_test/FormTestInputForgeryForm.
*/
namespace Drupal\form_test\Form;
use Drupal\Core\Form\FormBase;
use Symfony\Component\HttpFoundation\JsonResponse;
class FormTestInputForgeryForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return '_form_test_input_forgery';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
// For testing that a user can't submit a value not matching one of the
// allowed options.
$form['checkboxes'] = array(
'#title' => t('Checkboxes'),
'#type' => 'checkboxes',
'#options' => array(
'one' => 'One',
'two' => 'Two',
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
return new JsonResponse($form_state['values']);
}
}
<?php
/**
* @file
* Contains \Drupal\form_test\Form\FormTestTableSelectColspanForm.
*/
namespace Drupal\form_test\Form;
class FormTestTableSelectColspanForm extends FormTestTableSelectFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return '_form_test_tableselect_colspan_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
list($header, $options) = _form_test_tableselect_get_data();
// Change the data so that the third column has colspan=2.
$header['three'] = array('data' => 'Three', 'colspan' => 2);
unset($header['four']);
// Set the each row so that column 3 is an array.
foreach ($options as $name => $row) {
$options[$name]['three'] = array($row['three'], $row['four']);
unset($options[$name]['four']);
}
// Combine cells in row 3.
$options['row3']['one'] = array('data' => $options['row3']['one'], 'colspan' => 2);
unset($options['row3']['two']);
$options['row3']['three'] = array('data' => $options['row3']['three'][0], 'colspan' => 2);
unset($options['row3']['four']);
return $this->tableselectFormBuilder($form, $form_state, array('#header' => $header, '#options' => $options));
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
}
}
<?php
/**
* @file
* Contains \Drupal\form_test\Form\FormTestTableSelectEmptyForm.
*/
namespace Drupal\form_test\Form;
class FormTestTableSelectEmptyForm extends FormTestTableSelectFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return '_form_test_tableselect_empty_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
return $this->tableselectFormBuilder($form, $form_state, array('#options' => array()));
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
}
}
<?php
/**
* @file
* Contains \Drupal\form_test\Form\FormTestTableSelectFormBase.
*/
namespace Drupal\form_test\Form;
use Drupal\Core\Form\FormBase;
/**
* Provides a base class for tableselect forms.
*/
abstract class FormTestTableSelectFormBase extends FormBase {
/**
* Build a form to test the tableselect element.
*
* @param array $form
* An associative array containing the structure of the form.