You are here

public function ExcelExport::optionsSummary in Excel Serialization 8

Provides the default summary for options in the views UI.

This output is returned as an array.

Overrides RestExport::optionsSummary

File

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

Class

ExcelExport
Provides an Excel export display plugin.

Namespace

Drupal\xls_serialization\Plugin\views\display

Code

public function optionsSummary(&$categories, &$options) {
  parent::optionsSummary($categories, $options);

  // Excel sheet header formatting.
  $header_bold = $this
    ->getOption('header_bold') ? $this
    ->t('Bold') : $this
    ->t('Non-Bold');
  $header_italic = $this
    ->getOption('header_italic') ? $this
    ->t('Italic') : $this
    ->t('Non-Italic');
  $header_background_color = $this
    ->getOption('header_background_color') ? $this
    ->t('RGB code background color: @rgb_code', [
    '@rgb_code' => $this
      ->getOption('header_background_color'),
  ]) : $this
    ->t('No background color (white)');
  $format_header_value = implode(', ', [
    $header_bold,
    $header_italic,
    $header_background_color,
  ]);

  // Add category for Excel sheet header formatting.
  $categories['excel_sheet_header'] = [
    'title' => $this
      ->t('Excel sheet header'),
    'column' => 'second',
    'build' => [
      '#weight' => -1,
    ],
  ];

  // Add option for Excel sheet header formatting.
  $options['format_header'] = [
    'category' => 'excel_sheet_header',
    'title' => $this
      ->t('Format header'),
    'value' => $format_header_value,
  ];

  // Excel conditional formatting.
  $field_names = $this->view
    ->getDisplay()
    ->getFieldLabels();
  $operator_options = [
    0 => '=',
    1 => '<>',
  ];
  for ($i = 0; $i <= 4; $i++) {
    $current_conditional_formatting_base_field = $this
      ->getOption('conditional_formatting_base_field_' . $i);
    if ($current_conditional_formatting_base_field === 'Select a field' || $current_conditional_formatting_base_field === '' || $current_conditional_formatting_base_field === NULL) {
      $conditional_formatting_value[$i] = 'None';
    }
    else {
      $conditional_formatting_base_field[$i] = $this
        ->t('If Field @base_field', [
        '@base_field' => $field_names[$this
          ->getOption('conditional_formatting_base_field_' . $i)],
      ]);
      $conditional_formatting_operator[$i] = $operator_options[$this
        ->getOption('conditional_formatting_operator_' . $i)];
      $conditional_formatting_compare_to[$i] = '"' . $this
        ->getOption('conditional_formatting_compare_to_' . $i) . '"';
      $conditional_formatting_background_color[$i] = $this
        ->getOption('conditional_formatting_background_color_' . $i) ? $this
        ->t('then apply RGB code row background color: @rgb_code', [
        '@rgb_code' => $this
          ->getOption('conditional_formatting_background_color_' . $i),
      ]) : $this
        ->t('No background color');
      $conditional_formatting_value[$i] = implode(' ', [
        $conditional_formatting_base_field[$i],
        $conditional_formatting_operator[$i],
        $conditional_formatting_compare_to[$i],
        $conditional_formatting_background_color[$i],
      ]);
    }
  }

  // Add category for Excel conditional formatting.
  $categories['excel_conditional_formatting'] = [
    'title' => $this
      ->t('Excel conditional formatting'),
    'column' => 'second',
    'build' => [
      '#weight' => -1,
    ],
  ];

  // Add options for Excel conditional formatting.
  for ($i = 0; $i <= 4; $i++) {
    $options['excel_conditional_formatting_rules_' . $i] = [
      'category' => 'excel_conditional_formatting',
      'title' => $this
        ->t('Rule'),
      'value' => $conditional_formatting_value[$i],
    ];
  }

  // Add filename to the summary if set.
  if ($this
    ->getOption('filename')) {
    $options['path']['value'] .= $this
      ->t(': (@filename)', [
      '@filename' => $this
        ->getOption('filename'),
    ]);
  }

  // Display the selected format from the style plugin if available.
  $style_options = $this
    ->getOption('style')['options'];
  if (!empty($style_options['formats'])) {
    $options['style']['value'] .= $this
      ->t(': (@export_format)', [
      '@export_format' => reset($style_options['formats']),
    ]);
  }
}