function Boolean::buildOptionsForm

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/field/Boolean.php \Drupal\views\Plugin\views\field\Boolean::buildOptionsForm()
  2. 10 core/modules/views/src/Plugin/views/field/Boolean.php \Drupal\views\Plugin\views\field\Boolean::buildOptionsForm()
  3. 11.x core/modules/views/src/Plugin/views/field/Boolean.php \Drupal\views\Plugin\views\field\Boolean::buildOptionsForm()

Overrides FieldPluginBase::buildOptionsForm

File

core/modules/views/src/Plugin/views/field/Boolean.php, line 67

Class

Boolean
A handler to provide proper displays for booleans.

Namespace

Drupal\views\Plugin\views\field

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    foreach ($this->formats as $key => $item) {
        $options[$key] = implode('/', $item);
    }
    $form['type'] = [
        '#type' => 'select',
        '#title' => $this->t('Output format'),
        '#options' => $options,
        '#default_value' => $this->options['type'],
    ];
    $form['type_custom_true'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Custom output for TRUE'),
        '#default_value' => $this->options['type_custom_true'],
        '#states' => [
            'visible' => [
                'select[name="options[type]"]' => [
                    'value' => 'custom',
                ],
            ],
        ],
    ];
    $form['type_custom_false'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Custom output for FALSE'),
        '#default_value' => $this->options['type_custom_false'],
        '#states' => [
            'visible' => [
                'select[name="options[type]"]' => [
                    'value' => 'custom',
                ],
            ],
        ],
    ];
    $form['not'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Reverse'),
        '#description' => $this->t('If checked, true will be displayed as false.'),
        '#default_value' => $this->options['not'],
    ];
    parent::buildOptionsForm($form, $form_state);
}

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