You are here

public function FilterTestFormatForm::buildForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/filter/tests/filter_test/src/Form/FilterTestFormatForm.php \Drupal\filter_test\Form\FilterTestFormatForm::buildForm()
  2. 10 core/modules/filter/tests/filter_test/src/Form/FilterTestFormatForm.php \Drupal\filter_test\Form\FilterTestFormatForm::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/filter/tests/filter_test/src/Form/FilterTestFormatForm.php, line 25

Class

FilterTestFormatForm
Shows a test form for testing the 'text_format' form element.

Namespace

Drupal\filter_test\Form

Code

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

  // This ensures that the parent array key makes it into the HTML ID of the
  // form elements.
  $form['#tree'] = TRUE;
  $form['all_formats'] = [
    '#type' => 'details',
    '#title' => 'All text formats',
  ];
  $form['all_formats']['no_default'] = [
    '#type' => 'text_format',
    '#title' => 'No default value',
  ];
  $form['all_formats']['default'] = [
    '#type' => 'text_format',
    '#title' => 'Default value',
    '#format' => 'filter_test',
  ];
  $form['all_formats']['default_missing'] = [
    '#type' => 'text_format',
    '#title' => 'Missing default value',
    '#format' => 'missing_format',
  ];
  $form['restricted_formats'] = [
    '#type' => 'details',
    '#title' => 'Restricted text format list',
  ];
  $form['restricted_formats']['no_default'] = [
    '#type' => 'text_format',
    '#title' => 'No default value',
    '#allowed_formats' => [
      'full_html',
      'filter_test',
    ],
  ];
  $form['restricted_formats']['default'] = [
    '#type' => 'text_format',
    '#title' => 'Default value',
    '#format' => 'full_html',
    '#allowed_formats' => [
      'full_html',
      'filter_test',
    ],
  ];
  $form['restricted_formats']['default_missing'] = [
    '#type' => 'text_format',
    '#title' => 'Missing default value',
    '#format' => 'missing_format',
    '#allowed_formats' => [
      'full_html',
      'filter_test',
    ],
  ];
  $form['restricted_formats']['default_disallowed'] = [
    '#type' => 'text_format',
    '#title' => 'Disallowed default value',
    '#format' => 'filtered_html',
    '#allowed_formats' => [
      'full_html',
      'filter_test',
    ],
  ];
  $form['single_format'] = [
    '#type' => 'details',
    '#title' => 'Single text format',
  ];
  $form['single_format']['no_default'] = [
    '#type' => 'text_format',
    '#title' => 'No default value',
    '#allowed_formats' => [
      'filter_test',
    ],
  ];
  $form['single_format']['default'] = [
    '#type' => 'text_format',
    '#title' => 'Default value',
    '#format' => 'filter_test',
    '#allowed_formats' => [
      'filter_test',
    ],
  ];
  $form['single_format']['default_missing'] = [
    '#type' => 'text_format',
    '#title' => 'Missing default value',
    '#format' => 'missing_format',
    '#allowed_formats' => [
      'filter_test',
    ],
  ];
  $form['single_format']['default_disallowed'] = [
    '#type' => 'text_format',
    '#title' => 'Disallowed default value',
    '#format' => 'full_html',
    '#allowed_formats' => [
      'filter_test',
    ],
  ];
  return $form;
}