You are here

public function Views_Merge_RowsDisplayExtenderPlugin::get_options in Views Merge Rows 8

Returns configuration for row merging.

Only returns the configuration for the fields present in the view. If a new field was added to the view, the default configuration for this field is returned.

Return value

array Configuration for row merging.

2 calls to Views_Merge_RowsDisplayExtenderPlugin::get_options()
Views_Merge_RowsDisplayExtenderPlugin::optionsSummary in src/Plugin/views/display_extender/views_merge_rowsDisplayExtenderPlugin.php
Provide the default summary for options in the views UI.
Views_Merge_RowsDisplayExtenderPlugin::views_merge_rows_options_form_build in src/Plugin/views/display_extender/views_merge_rowsDisplayExtenderPlugin.php
Provide a form to edit options for this plugin.

File

src/Plugin/views/display_extender/views_merge_rowsDisplayExtenderPlugin.php, line 43
Contains the class to extend views display with rows merge functionality.

Class

Views_Merge_RowsDisplayExtenderPlugin
Plugin annotation @ViewsDisplayExtender( id = "views_merge_rows", title = @Translation("Merge rows"), help = @Translation("Merges rows with the same values in the specified fields."), no_ui = FALSE )

Namespace

Drupal\views_merge_rows\Plugin\views\display_extender

Code

public function get_options() {
  if ($this->displayHandler
    ->usesFields()) {
    $options = [];
    $options['merge_rows'] = $this->displayHandler
      ->getOption('merge_rows');
    if (empty($options['merge_rows'])) {
      $options['merge_rows'] = FALSE;
    }
    $options['use_grouping'] = $this->displayHandler
      ->getOption('use_grouping');
    if (empty($options['use_grouping'])) {
      $options['use_grouping'] = FALSE;
    }
    $options['field_config'] = [];
    $field_config = $this->displayHandler
      ->getOption('field_config');
    $fields = $this->displayHandler
      ->getOption('fields');
    foreach ($fields as $field => $info) {
      if (isset($field_config[$field])) {
        $options['field_config'][$field] = $field_config[$field];
      }
      else {
        $options['field_config'][$field] = [
          'merge_option' => 'merge_unique',
          'exclude_first' => FALSE,
          'prefix' => '',
          'separator' => ', ',
          'suffix' => '',
        ];
      }
    }
  }
  else {
    $options['merge_rows'] = FALSE;
    $options['use_grouping'] = FALSE;
    $options['field_config'] = [];
  }
  return $options;
}