function EntityField::buildOptionsForm

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

Overrides FieldPluginBase::buildOptionsForm

1 call to EntityField::buildOptionsForm()
TermName::buildOptionsForm in core/modules/taxonomy/src/Plugin/views/field/TermName.php
Default options form that provides the label widget that all fields should have.
1 method overrides EntityField::buildOptionsForm()
TermName::buildOptionsForm in core/modules/taxonomy/src/Plugin/views/field/TermName.php
Default options form that provides the label widget that all fields should have.

File

core/modules/views/src/Plugin/views/field/EntityField.php, line 454

Class

EntityField
A field that displays entity field data.

Namespace

Drupal\views\Plugin\views\field

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);
    $field = $this->getFieldDefinition();
    $formatters = $this->formatterPluginManager
        ->getOptions($field->getType());
    $column_names = array_keys($field->getColumns());
    // If this is a multiple value field, add its options.
    if ($this->multiple) {
        $this->multiple_options_form($form, $form_state);
    }
    // No need to ask the user anything if the field has only one column.
    if (count($field->getColumns()) == 1) {
        $form['click_sort_column'] = [
            '#type' => 'value',
            '#value' => isset($column_names[0]) ? $column_names[0] : '',
        ];
    }
    else {
        $form['click_sort_column'] = [
            '#type' => 'select',
            '#title' => $this->t('Column used for click sorting'),
            '#options' => array_combine($column_names, $column_names),
            '#default_value' => $this->options['click_sort_column'],
            '#description' => $this->t('Used by Style: Table to determine the actual column to click sort the field on. The default is usually fine.'),
        ];
    }
    $form['type'] = [
        '#type' => 'select',
        '#title' => $this->t('Formatter'),
        '#options' => $formatters,
        '#default_value' => $this->options['type'],
        '#ajax' => [
            'url' => views_ui_build_form_url($form_state),
        ],
        '#submit' => [
            [
                $this,
                'submitTemporaryForm',
            ],
        ],
        '#executes_submit_callback' => TRUE,
    ];
    $form['field_api_classes'] = [
        '#title' => $this->t('Use field template'),
        '#type' => 'checkbox',
        '#default_value' => $this->options['field_api_classes'],
        '#description' => $this->t('If checked, field api classes will be added by field templates. This is not recommended unless your CSS depends upon these classes. If not checked, template will not be used.'),
        '#fieldset' => 'style_settings',
        '#weight' => 20,
    ];
    if ($this->multiple) {
        $form['field_api_classes']['#description'] .= ' ' . $this->t('Checking this option will cause the group Display Type and Separator values to be ignored.');
    }
    // Get the settings form.
    $settings_form = [
        '#value' => [],
    ];
    $format = isset($form_state->getUserInput()['options']['type']) ? $form_state->getUserInput()['options']['type'] : $this->options['type'];
    if ($formatter = $this->getFormatterInstance($format)) {
        $settings_form = $formatter->settingsForm($form, $form_state);
        // Convert field UI selector states to work in the Views field form.
        FormHelper::rewriteStatesSelector($settings_form, "fields[{$field->getName()}][settings_edit_form]", 'options');
    }
    $form['settings'] = $settings_form;
}

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