function FieldFormButtonTest::viewsForm

Same name in other branches
  1. 9 core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldFormButtonTest.php \Drupal\views_test_data\Plugin\views\field\FieldFormButtonTest::viewsForm()
  2. 8.9.x core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldFormButtonTest.php \Drupal\views_test_data\Plugin\views\field\FieldFormButtonTest::viewsForm()
  3. 10 core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldFormButtonTest.php \Drupal\views_test_data\Plugin\views\field\FieldFormButtonTest::viewsForm()

Form constructor for the views form.

Parameters

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

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

File

core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldFormButtonTest.php, line 38

Class

FieldFormButtonTest
A handler to provide a field that is completely custom by the administrator.

Namespace

Drupal\views_test_data\Plugin\views\field

Code

public function viewsForm(&$form, FormStateInterface $form_state) {
    // Make sure we do not accidentally cache this form.
    $form['#cache']['max-age'] = 0;
    // The view is empty, abort.
    if (empty($this->view->result)) {
        unset($form['actions']);
        return;
    }
    $form[$this->options['id']]['#tree'] = TRUE;
    foreach ($this->view->result as $row_index => $row) {
        $form[$this->options['id']][$row_index] = [
            '#type' => 'submit',
            '#value' => $this->t('Test Button'),
            '#name' => 'test-button-' . $row_index,
            '#test_button' => TRUE,
            '#row_index' => $row_index,
            '#attributes' => [
                'class' => [
                    'test-button',
                ],
            ],
        ];
    }
}

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