You are here

public function ViewsMergeRowsDisplayExtenderPlugin::getOptions in Views Merge Rows 8.2

Returns configuration for row merging.

Only returns the configuration for the fields present in the view. In case configuration still has some entries about removed fields.

If a new field was added to the view, the default configuration for this field is returned.

Impossible to provide default field values for fields in ::defineOptions() because displayHandler property is not available at this moment.

Return value

array Configuration for row merging.

File

src/Plugin/views/display_extender/ViewsMergeRowsDisplayExtenderPlugin.php, line 242

Class

ViewsMergeRowsDisplayExtenderPlugin
Provides interface to manage merge options on a per-field basis.

Namespace

Drupal\views_merge_rows\Plugin\views\display_extender

Code

public function getOptions() : array {
  $options = [
    'merge_rows' => FALSE,
    'field_config' => [],
  ];
  if ($this->displayHandler
    ->usesFields()) {
    $options['merge_rows'] = $this->options['merge_rows'];
    $field_default_options = [
      'merge_option' => 'merge_unique',
      'exclude_first' => FALSE,
      'prefix' => '',
      'separator' => ', ',
      'suffix' => '',
    ];
    $fields = $this->displayHandler
      ->getOption('fields');
    foreach (array_keys($fields) as $field) {
      $options['field_config'][$field] = $field_default_options;
      if (isset($this->options['field_config'][$field])) {
        $options['field_config'][$field] = $this->options['field_config'][$field] + $field_default_options;
      }
    }
  }
  return $options;
}