You are here

public function Fields::buildOptionsForm in Layout Plugin Views 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/views/row/Fields.php \Drupal\layout_plugin_views\Plugin\views\row\Fields::buildOptionsForm()

Provide a form for setting options.

Overrides Fields::buildOptionsForm

File

src/Plugin/views/row/Fields.php, line 80

Class

Fields
The layout_plugin_views 'fields' row plugin

Namespace

Drupal\layout_plugin_views\Plugin\views\row

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  if ($this->pluginOptions
    ->hasValidSelectedLayout()) {
    $layout_definition = $this->pluginOptions
      ->getSelectedLayoutDefinition();
  }
  elseif ($this->pluginOptions
    ->layoutFallbackIsPossible()) {
    $layout_definition = $this->pluginOptions
      ->getFallbackLayoutDefinition();
  }
  if (!empty($layout_definition)) {
    $form['layout'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Panel layout'),
      '#options' => $this->layoutPluginManager
        ->getLayoutOptions([
        'group_by_category' => TRUE,
      ]),
      '#default_value' => $layout_definition['id'],
    ];
    $form['default_region'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Default region'),
      '#description' => $this
        ->t('Defines the region in which the fields will be rendered by default.'),
      '#options' => $layout_definition['region_names'],
      '#default_value' => $this->pluginOptions
        ->getDefaultRegion(),
    ];
    $form['assigned_regions'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Assign regions'),
      '#description' => $this
        ->t('You can use the dropdown menus above to select a region for each field to be rendered in.'),
    ];
    foreach ($this->displayHandler
      ->getFieldLabels() as $field_name => $field_label) {
      $form['assigned_regions'][$field_name] = [
        '#type' => 'select',
        '#options' => $layout_definition['region_names'],
        '#title' => $field_label,
        '#default_value' => $this->pluginOptions
          ->getAssignedRegion($field_name),
        '#empty_option' => $this
          ->t('Default region'),
      ];
    }
  }
}