You are here

public function TableSecondaryRow::buildOptionsForm in Views Secondary Row 8

Render the given style. The options form will use template_preprocess_views_secondary_row_style_plugin_table.

Overrides Table::buildOptionsForm

File

src/Plugin/views/style/TableSecondaryRow.php, line 46

Class

TableSecondaryRow
Style plugin to render each item as a row in a table.

Namespace

Drupal\views_secondary_row\Plugin\views\style

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $handlers = $this->displayHandler
    ->getHandlers('field');
  if (empty($handlers)) {
    return;
  }

  // Note: views UI registers this theme handler on our behalf. Your module
  // will have to register your theme handlers if you do stuff like this.
  // $form['#theme'] = 'views_ui_style_plugin_table';
  $form['#theme'] = 'views_secondary_row_style_plugin_table';
  $columns = $this
    ->sanitizeColumns($this->options['columns']);

  // Create an array of allowed columns from the data we know:
  $field_names = [
    '' => $this
      ->t('None'),
  ] + $this->displayHandler
    ->getFieldLabels();
  foreach ($columns as $field => $column) {
    $column_selector = ':input[name="style_options[columns][' . $field . ']"]';
    $column_selector2 = ':input[name="style_options[break2][' . $field . ']"]';
    $form['info'][$field]['break2'] = [
      '#title' => $this
        ->t('Break for @field', [
        '@field' => $field,
      ]),
      '#title_display' => 'invisible',
      '#type' => 'select',
      '#default_value' => isset($this->options['info'][$field]['break2']) ? $this->options['info'][$field]['break2'] : '',
      '#options' => $field_names,
      '#states' => [
        'visible' => [
          $column_selector => [
            'value' => $field,
          ],
        ],
      ],
    ];
    $form['info'][$field]['separator2'] = [
      '#title' => $this
        ->t('Separator for @field', [
        '@field' => $field,
      ]),
      '#title_display' => 'invisible',
      '#type' => 'textfield',
      '#size' => 10,
      '#default_value' => isset($this->options['info'][$field]['separator2']) ? $this->options['info'][$field]['separator2'] : '',
      '#states' => [
        'visible' => [
          $column_selector => [
            'value' => $field,
          ],
        ],
        'invisible' => [
          $column_selector2 => [
            'value' => '',
          ],
        ],
      ],
    ];
    $form['info'][$field]['colspan2'] = [
      '#title' => $this
        ->t('Colspan for @field', [
        '@field' => $field,
      ]),
      '#title_display' => 'invisible',
      '#type' => 'textfield',
      '#size' => 5,
      '#default_value' => isset($this->options['info'][$field]['colspan2']) ? $this->options['info'][$field]['colspan2'] : '',
      '#states' => [
        'visible' => [
          $column_selector => [
            'value' => $field,
          ],
        ],
        'invisible' => [
          $column_selector2 => [
            'value' => '',
          ],
        ],
      ],
    ];
  }
}