You are here

public function FieldFormButtonTest::viewsForm in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldFormButtonTest.php \Drupal\views_test_data\Plugin\views\field\FieldFormButtonTest::viewsForm()
  2. 9 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 36

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' => t('Test Button'),
      '#name' => 'test-button-' . $row_index,
      '#test_button' => TRUE,
      '#row_index' => $row_index,
      '#attributes' => [
        'class' => [
          'test-button',
        ],
      ],
    ];
  }
}