You are here

public function DrupalSliderViewsField::buildOptionsForm in Drupal Slider 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/views/field/DrupalSliderViewsField.php \Drupal\drupal_slider\Plugin\views\field\DrupalSliderViewsField::buildOptionsForm()

Provide the options form.

Overrides FieldPluginBase::buildOptionsForm

File

src/Plugin/views/field/DrupalSliderViewsField.php, line 46

Class

DrupalSliderViewsField
Field handler for Drupal Slider.

Namespace

Drupal\drupal_slider\Plugin\views\field

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  $form['relationship']['#access'] = FALSE;
  $slide_options = [];
  $entity = \Drupal::entityTypeManager()
    ->getStorage('drupal_slider_slide_grouping')
    ->loadMultiple();
  foreach ($entity as $key => $value) {
    $slide_options[$key] = $value->label;
  }
  $form['slide_options'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Slide options'),
    '#options' => $slide_options,
    '#default_value' => $this->options['slide_options'],
    '#description' => $this
      ->t('Choose slides option set'),
    '#required' => TRUE,
  ];
  $form['background_img'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Background Image'),
    '#description' => $this
      ->t("Give the background image URL token"),
    '#default_value' => $this->options['background_img'],
  ];
  $config = \Drupal::config('drupal_slider.settings');
  $layers_count = $config
    ->get('ds_layers_count');
  for ($i = 1; $i <= $layers_count; $i++) {
    $form['layer_' . $i] = [
      '#type' => 'textarea',
      '#title' => 'Layer ' . $i,
      '#description' => $this
        ->t('Use any text, image etc.'),
      '#default_value' => $this->options['layer_' . $i],
    ];
  }
  $form['replacements'] = [
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => $this
      ->t('Replacement Variables'),
  ];
  $views_fields = $this->view->display_handler
    ->getHandlers('field');
  foreach ($views_fields as $field => $handler) {
    if ($field == $this->options['id']) {
      break;
    }
    $items[] = "{{ {$field} }}";
  }
  $form['replacements']['variables'] = [
    '#theme' => 'item_list',
    '#items' => $items,
  ];
  parent::buildOptionsForm($form, $form_state);
}