You are here

public function ExcelExport::buildOptionsForm in Excel Serialization 8

Same name in this branch
  1. 8 src/Plugin/views/display/ExcelExport.php \Drupal\xls_serialization\Plugin\views\display\ExcelExport::buildOptionsForm()
  2. 8 src/Plugin/views/style/ExcelExport.php \Drupal\xls_serialization\Plugin\views\style\ExcelExport::buildOptionsForm()

Provide a form to edit options for this plugin.

Overrides RestExport::buildOptionsForm

File

src/Plugin/views/display/ExcelExport.php, line 192

Class

ExcelExport
Provides an Excel export display plugin.

Namespace

Drupal\xls_serialization\Plugin\views\display

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  switch ($form_state
    ->get('section')) {
    case 'style':

      // Remove the 'serializer' and 'data_export'
      // (if available) options to avoid confusion.
      unset($form['style']['type']['#options']['serializer']);
      unset($form['style']['type']['#options']['data_export']);
      break;
    case 'path':
      $form['filename'] = [
        '#type' => 'textfield',
        '#title' => $this
          ->t('Filename'),
        '#default_value' => $this
          ->getOption('filename'),
        '#description' => $this
          ->t('The filename that will be suggested to the browser for downloading purposes. You may include replacement patterns from the list below.'),
      ];

      // Support tokens.
      $this
        ->globalTokenForm($form, $form_state);
      break;
    case 'format_header':
      $form['#title'] .= $this
        ->t('Format header');
      $form['header_bold'] = [
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Header Bold'),
        '#default_value' => $this
          ->getOption('header_bold'),
        '#description' => $this
          ->t('Do you want to make the header (first row) of the worksheet bold?'),
      ];
      $form['header_italic'] = [
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Header Italic'),
        '#default_value' => $this
          ->getOption('header_italic'),
        '#description' => $this
          ->t('Do you want to make the header (first row) of the worksheet italic?'),
      ];
      $form['header_background_color'] = [
        '#type' => 'textfield',
        '#title' => $this
          ->t('Header Background Color'),
        '#default_value' => $this
          ->getOption('header_background_color'),
        '#description' => $this
          ->t("Give the RGB code for the background color of the worksheet's header. Leave empty for default color."),
        '#size' => 6,
        '#maxlength' => 6,
      ];
      break;
  }
  $field_names = $this->view
    ->getDisplay()
    ->getFieldLabels();
  $form['#title'] .= $this
    ->t('Conditional formatting rules');
  for ($i = 0; $i <= 4; $i++) {
    if ($form_state
      ->get('section') === 'excel_conditional_formatting_rules_' . $i) {
      $form['conditional_formatting_base_field_' . $i] = [
        '#type' => 'select',
        '#options' => $field_names,
        '#empty_value' => 'Select a field',
        '#title' => $this
          ->t('Field used to compare to text'),
        '#default_value' => $this
          ->getOption('conditional_formatting_base_field_' . $i),
      ];
      $form['conditional_formatting_operator_' . $i] = [
        '#type' => 'select',
        '#options' => [
          '=',
          '<>',
        ],
        '#empty_value' => 'Select an operator',
        '#title' => $this
          ->t('Operator'),
        '#default_value' => $this
          ->getOption('conditional_formatting_operator_' . $i),
      ];
      $form['conditional_formatting_compare_to_' . $i] = [
        '#type' => 'textfield',
        '#empty_value' => 'Select an operator',
        '#title' => $this
          ->t('Text to compare to'),
        '#default_value' => $this
          ->getOption('conditional_formatting_compare_to_' . $i),
      ];
      $form['conditional_formatting_background_color_' . $i] = [
        '#type' => 'textfield',
        '#title' => $this
          ->t('Row Background Color'),
        '#default_value' => $this
          ->getOption('conditional_formatting_background_color_' . $i),
        '#description' => $this
          ->t("Give the RGB code for the background color of the row. Leave empty for default color."),
        '#size' => 6,
        '#maxlength' => 6,
      ];
    }
  }
}