You are here

public function CallbackSerializer::buildOptionsForm in Search Autocomplete 8

Same name and namespace in other branches
  1. 2.x src/Plugin/views/style/CallbackSerializer.php \Drupal\search_autocomplete\Plugin\views\style\CallbackSerializer::buildOptionsForm()

Provide a form to edit options for this plugin.

Overrides StylePluginBase::buildOptionsForm

File

src/Plugin/views/style/CallbackSerializer.php, line 58

Class

CallbackSerializer
The style plugin for serialized output formats.

Namespace

Drupal\search_autocomplete\Plugin\views\style

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);

  // Unset unecessary configurations.
  unset($form['grouping']['0']['rendered']);
  unset($form['grouping']['0']['rendered_strip']);
  unset($form['grouping']['0']['rendered_strip']);
  unset($form['grouping']['1']);

  // Add custom options.
  $field_labels = $this->displayHandler
    ->getFieldLabels(TRUE);

  // Build the input field option.
  $input_label_descr = (empty($field_labels) ? '<b>' . $this
    ->t('Warning') . ': </b> ' . $this
    ->t('Requires at least one field in the view.') . '<br/>' : '') . $this
    ->t('Select the autocompletion input value. If the autocompletion settings are set to auto-submit, this value will be submitted as the suggestion is selected.');
  $form['input_label'] = [
    '#title' => $this
      ->t('Input Label'),
    '#type' => 'select',
    '#description' => new HtmlEscapedText($input_label_descr),
    '#default_value' => $this->options['input_label'],
    '#disabled' => empty($field_labels),
    '#required' => TRUE,
    '#options' => $field_labels,
  ];

  // Build the link field option.
  $input_link_descr = (empty($field_labels) ? '<b>' . $this
    ->t('Warning') . ': </b> ' . $this
    ->t('Requires at least one field in the view.') . '<br/>' : '') . $this
    ->t('Select the autocompletion input link. If the autocompletion settings are set to auto-redirect, this link is where the user will be redirected as the suggestion is selected.');
  $form['input_link'] = [
    '#title' => $this
      ->t('Input Link'),
    '#type' => 'select',
    '#description' => new HtmlEscapedText($input_link_descr),
    '#default_value' => $this->options['input_link'],
    '#disabled' => empty($field_labels),
    '#required' => TRUE,
    '#options' => $field_labels,
  ];
}