You are here

public function FormTestCheckboxesRadiosForm::buildForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxesRadiosForm.php \Drupal\form_test\Form\FormTestCheckboxesRadiosForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxesRadiosForm.php, line 29
Contains \Drupal\form_test\Form\FormTestCheckboxesRadiosForm.

Class

FormTestCheckboxesRadiosForm
Form constructor to test expansion of #type checkboxes and radios.

Namespace

Drupal\form_test\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $customize = FALSE) {

  // Expand #type checkboxes, setting custom element properties for some but not
  // all options.
  $form['checkboxes'] = array(
    '#type' => 'checkboxes',
    '#title' => 'Checkboxes',
    '#options' => array(
      0 => 'Zero',
      'foo' => 'Foo',
      1 => 'One',
      'bar' => $this
        ->t('<em>Bar - checkboxes</em>'),
      '>' => "<em>Special Char</em><script>alert('checkboxes');</script>",
    ),
  );
  if ($customize) {
    $form['checkboxes'] += array(
      'foo' => array(
        '#description' => 'Enable to foo.',
      ),
      1 => array(
        '#weight' => 10,
      ),
    );
  }

  // Expand #type radios, setting custom element properties for some but not
  // all options.
  $form['radios'] = array(
    '#type' => 'radios',
    '#title' => 'Radios',
    '#options' => array(
      0 => 'Zero',
      'foo' => 'Foo',
      1 => 'One',
      'bar' => '<em>Bar - radios</em>',
      '>' => "<em>Special Char</em><script>alert('radios');</script>",
    ),
  );
  if ($customize) {
    $form['radios'] += array(
      'foo' => array(
        '#description' => 'Enable to foo.',
      ),
      1 => array(
        '#weight' => 10,
      ),
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
  );
  return $form;
}