You are here

public function ViewsLayoutStyle::buildOptionsForm in Views Layout 8

Builds the configuration form.

Overrides StylePluginBase::buildOptionsForm

File

src/Plugin/views/style/ViewsLayoutStyle.php, line 120

Class

ViewsLayoutStyle
Style plugin for the timeline view.

Namespace

Drupal\views_layout\Plugin\views\style

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $header = [
    'icon' => $this
      ->t('Icon'),
    'name' => $this
      ->t('Name'),
  ];
  $form['layout_name'] = [
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $this->layouts,
    '#default_value' => $this->options['layout_name'],
    '#multiple' => FALSE,
  ];
  foreach ($this->regions as $plugin_id => $region) {
    $default_values = $this->options['layout_name'] == $plugin_id ? $this->options['layout_regions'][$plugin_id] : [];
    $form['layout_regions'][$plugin_id] = [
      '#type' => 'checkboxes',
      '#options' => $region['regions'],
      '#title' => $this
        ->t(':name Regions', [
        ':name' => $region['label'],
      ]),
      '#description' => $this
        ->t("Check the regions in this layout that should be populated with Views results. Uncheck any regions that should be skipped. Skipped regions will not contain any results."),
      '#default_value' => !empty($this->options['layout_regions'][$plugin_id]) ? $this->options['layout_regions'][$plugin_id] : '',
      '#multiple' => TRUE,
      '#states' => [
        'visible' => [
          ':input[name="style_options[layout_name]"]' => [
            'value' => $plugin_id,
          ],
        ],
      ],
    ];
  }
  $form['skip_processing'] = [
    '#type' => 'select',
    '#options' => [
      '' => $this
        ->t('Skip'),
      'text' => $this
        ->t('Text'),
      'callback' => $this
        ->t('Callback'),
    ],
    '#description' => $this
      ->t('Choose processing for unchecked regions: skip (do not render), generate text, or execute a callback.'),
    '#title' => $this
      ->t('What to do with skipped regions?'),
    '#default_value' => $this->options['skip_processing'],
  ];
  $form['skip_text'] = [
    '#type' => 'text_format',
    '#description' => $this
      ->t('Text to render in skipped regions.'),
    '#title' => $this
      ->t('Skipped regions text'),
    '#default_value' => $this->options['skip_text']['value'],
    '#format' => $this->options['skip_text']['format'],
    '#states' => [
      'visible' => [
        ':input[name="style_options[skip_processing]"]' => [
          'value' => 'text',
        ],
      ],
    ],
  ];
  $form['callback'] = [
    '#type' => 'textfield',
    '#description' => $this
      ->t('Callback for skipped regions. Callback arguments are the layout plugin id, the current region, and the view.'),
    '#title' => $this
      ->t('Skipped regions callback'),
    '#default_value' => $this->options['callback'],
    '#states' => [
      'visible' => [
        ':input[name="style_options[skip_processing]"]' => [
          'value' => 'callback',
        ],
      ],
    ],
  ];
  $form['#element_validate'] = [
    [
      $this,
      'validateRegions',
    ],
  ];
}