You are here

public function Attachment::buildOptionsForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/display/Attachment.php \Drupal\views\Plugin\views\display\Attachment::buildOptionsForm()

Provide the default form for setting options.

Overrides DisplayPluginBase::buildOptionsForm

File

core/modules/views/src/Plugin/views/display/Attachment.php, line 138

Class

Attachment
The plugin that handles an attachment display.

Namespace

Drupal\views\Plugin\views\display

Code

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

  // It is very important to call the parent function here:
  parent::buildOptionsForm($form, $form_state);
  switch ($form_state
    ->get('section')) {
    case 'inherit_arguments':
      $form['#title'] .= $this
        ->t('Inherit contextual filters');
      $form['inherit_arguments'] = [
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Inherit'),
        '#description' => $this
          ->t('Should this display inherit its contextual filter values from the parent display to which it is attached?'),
        '#default_value' => $this
          ->getOption('inherit_arguments'),
      ];
      break;
    case 'inherit_exposed_filters':
      $form['#title'] .= $this
        ->t('Inherit exposed filters');
      $form['inherit_exposed_filters'] = [
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Inherit'),
        '#description' => $this
          ->t('Should this display inherit its exposed filter values from the parent display to which it is attached?'),
        '#default_value' => $this
          ->getOption('inherit_exposed_filters'),
      ];
      break;
    case 'inherit_pager':
      $form['#title'] .= $this
        ->t('Inherit pager');
      $form['inherit_pager'] = [
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Inherit'),
        '#description' => $this
          ->t('Should this display inherit its paging values from the parent display to which it is attached?'),
        '#default_value' => $this
          ->getOption('inherit_pager'),
      ];
      break;
    case 'render_pager':
      $form['#title'] .= $this
        ->t('Render pager');
      $form['render_pager'] = [
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Render'),
        '#description' => $this
          ->t('Should this display render the pager values? This is only meaningful if inheriting a pager.'),
        '#default_value' => $this
          ->getOption('render_pager'),
      ];
      break;
    case 'attachment_position':
      $form['#title'] .= $this
        ->t('Position');
      $form['attachment_position'] = [
        '#title' => $this
          ->t('Position'),
        '#type' => 'radios',
        '#description' => $this
          ->t('Attach before or after the parent display?'),
        '#options' => $this
          ->attachmentPositions(),
        '#default_value' => $this
          ->getOption('attachment_position'),
      ];
      break;
    case 'displays':
      $form['#title'] .= $this
        ->t('Attach to');
      $displays = [];
      foreach ($this->view->storage
        ->get('display') as $display_id => $display) {
        if ($this->view->displayHandlers
          ->has($display_id) && $this->view->displayHandlers
          ->get($display_id)
          ->acceptAttachments()) {
          $displays[$display_id] = $display['display_title'];
        }
      }
      $form['displays'] = [
        '#title' => $this
          ->t('Displays'),
        '#type' => 'checkboxes',
        '#description' => $this
          ->t('Select which display or displays this should attach to.'),
        '#options' => array_map('\\Drupal\\Component\\Utility\\Html::escape', $displays),
        '#default_value' => $this
          ->getOption('displays'),
      ];
      break;
  }
}