tableselectFormBuilder example

/** * {@inheritdoc} */
  public function getFormId() {
    return '_form_test_tableselect_empty_form';
  }

  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state) {
    return $this->tableselectFormBuilder($form$form_state['#options' => []]);
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
  }

}
/** * {@inheritdoc} */
  public function getFormId() {
    return '_form_test_tableselect_multiple_false_form';
  }

  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state) {
    return $this->tableselectFormBuilder($form$form_state['#multiple' => FALSE]);
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->messenger()->addStatus($this->t('Submitted: @value', ['@value' => $form_state->getValue('tableselect')]));
  }

}

  public function getFormId() {
    return '_form_test_tableselect_disabled_rows_form';
  }

  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state$test_action = NULL) {
    $multiple = ['multiple-true' => TRUE, 'multiple-false' => FALSE][$test_action];
    $form = $this->tableselectFormBuilder($form$form_state[
      '#multiple' => $multiple,
      '#js_select' => TRUE,
      '#ajax' => NULL,
    ]);

    // Disable the second row.     $form['tableselect']['#options']['row2']['#disabled'] = TRUE;

    return $form;
  }

  
break;

      case 'multiple-true-no-advanced-select':
        $options = ['#multiple' => TRUE, '#js_select' => FALSE];
        break;

      case 'multiple-false-advanced-select':
        $options = ['#multiple' => FALSE, '#js_select' => TRUE];
        break;
    }

    return $this->tableselectFormBuilder($form$form_state$options);
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
  }

}
/** * {@inheritdoc} */
  public function getFormId() {
    return '_form_test_tableselect_multiple_true_form';
  }

  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state) {
    return $this->tableselectFormBuilder($form$form_state['#multiple' => TRUE]);
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $selected = $form_state->getValue('tableselect');
    foreach ($selected as $key => $value) {
      $this->messenger()->addStatus($this->t('Submitted: @key = @value', ['@key' => $key, '@value' => $value]));
    }
  }

}
// Set the each row so that column 3 is an array.     foreach ($options as $name => $row) {
      $options[$name]['three'] = [$row['three']$row['four']];
      unset($options[$name]['four']);
    }
    // Combine cells in row 3.     $options['row3']['one'] = ['data' => $options['row3']['one'], 'colspan' => 2];
    unset($options['row3']['two']);
    $options['row3']['three'] = ['data' => $options['row3']['three'][0], 'colspan' => 2];
    unset($options['row3']['four']);

    return $this->tableselectFormBuilder($form$form_state['#header' => $header, '#options' => $options]);
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
  }

}
Home | Imprint | This part of the site doesn't use cookies.