FormTestTableForm.php

Same filename in other branches
  1. 9 core/modules/system/tests/modules/form_test/src/Form/FormTestTableForm.php
  2. 8.9.x core/modules/system/tests/modules/form_test/src/Form/FormTestTableForm.php
  3. 11.x core/modules/system/tests/modules/form_test/src/Form/FormTestTableForm.php

Namespace

Drupal\form_test\Form

File

core/modules/system/tests/modules/form_test/src/Form/FormTestTableForm.php

View source
<?php

namespace Drupal\form_test\Form;

use Drupal\Core\Form\FormStateInterface;

/**
 * Form constructor for testing #type 'table' elements.
 *
 * @internal
 */
class FormTestTableForm extends FormTestTableSelectFormBase {
    
    /**
     * {@inheritdoc}
     */
    public function getFormId() {
        return '_form_test_table_form';
    }
    
    /**
     * {@inheritdoc}
     */
    public function buildForm(array $form, FormStateInterface $form_state) {
        $form['table'] = [
            '#type' => 'table',
            '#tableselect' => TRUE,
            '#empty' => $this->t('Empty text.'),
        ];
        $form['table']['row'] = [
            'data' => [
                '#title' => '<em>kitten</em>',
                '#markup' => '<p>some text</p>',
            ],
        ];
        $form['table']['another_row'] = [
            'data' => [
                '#title' => $this->t('my favorite fruit is <strong>@fruit</strong>', [
                    '@fruit' => 'bananas',
                ]),
                '#markup' => '<p>some more text</p>',
            ],
        ];
        return $form;
    }
    
    /**
     * {@inheritdoc}
     */
    public function submitForm(array &$form, FormStateInterface $form_state) {
    }

}

Classes

Title Deprecated Summary
FormTestTableForm Form constructor for testing #type 'table' elements.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.