af41782cb3e1c2f10cbf805f421980321abba67f
[yaffs-website] / web / core / modules / system / tests / modules / form_test / src / Form / FormTestTableSelectFormBase.php
1 <?php
2
3 namespace Drupal\form_test\Form;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Provides a base class for tableselect forms.
10  *
11  * @internal
12  */
13 abstract class FormTestTableSelectFormBase extends FormBase {
14
15   /**
16    * Build a form to test the tableselect element.
17    *
18    * @param array $form
19    *   An associative array containing the structure of the form.
20    * @param \Drupal\Core\Form\FormStateInterface $form_state
21    *   The current state of the form.
22    * @param $element_properties
23    *   An array of element properties for the tableselect element.
24    *
25    * @return array
26    *   A form with a tableselect element and a submit button.
27    */
28   public function tableselectFormBuilder($form, FormStateInterface $form_state, $element_properties) {
29     list($header, $options) = _form_test_tableselect_get_data();
30
31     $form['tableselect'] = $element_properties;
32
33     $form['tableselect'] += [
34       '#prefix' => '<div id="tableselect-wrapper">',
35       '#suffix' => '</div>',
36       '#type' => 'tableselect',
37       '#header' => $header,
38       '#options' => $options,
39       '#multiple' => FALSE,
40       '#empty' => t('Empty text.'),
41       '#ajax' => [
42         'callback' => 'form_test_tableselect_ajax_callback',
43         'wrapper' => 'tableselect-wrapper',
44       ],
45     ];
46
47     $form['submit'] = [
48       '#type' => 'submit',
49       '#value' => t('Submit'),
50     ];
51
52     return $form;
53   }
54
55 }