You are here

public function Fieldset::buildOptionsForm in Views fieldsets 8.3

Default options form that provides the label widget that all fields should have.

Overrides FieldPluginBase::buildOptionsForm

File

src/Plugin/views/field/Fieldset.php, line 154

Class

Fieldset
@ViewsField("fieldset").

Namespace

Drupal\views_fieldsets\Plugin\views\field

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  $fake_form = [];
  parent::buildOptionsForm($fake_form, $form_state);
  $form['admin_label'] = $fake_form['admin_label'];
  $form['fields'] = [
    '#type' => 'value',
    '#value' => $this->options['fields'],
  ];
  $help_token = $this
    ->t('With row tokens, eg. <code>{{ title }}</code>.');
  $form['wrapper'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Wrapper type'),
    '#options' => self::getWrapperTypes(),
    '#default_value' => $this->options['wrapper'],
    '#required' => TRUE,
  ];
  $form['legend'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Fieldset legend'),
    '#default_value' => $this->options['legend'],
    '#description' => $help_token,
  ];
  $form['classes'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Wrapper classes'),
    '#default_value' => $this->options['classes'],
    '#description' => $help_token . ' ' . $this
      ->t('Separate classes with DOUBLE SPACES. Single spaces and much else will be converted to valid class name.'),
  ];
  $form['collapsible'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Collapsible'),
    '#default_value' => $this->options['collapsible'],
  ];
  $form['collapsed'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Collapsed'),
    '#default_value' => $this->options['collapsed'],
  ];

  /* Available tokens list. Not as pretty as FieldPluginBase,
   * because it doesn't have a reusable method.
   */
  $form['tokens'] = [
    '#theme' => 'item_list',
    '#title' => $this
      ->t('Replacement patterns'),
    '#items' => array_map(function ($token) {
      return Markup::create("<code>{$token}</code>");
    }, array_keys($this
      ->getRenderTokens([]))),
  ];
}