You are here

public function MarkerDefault::renderGroupingSets in Leaflet 2.0.x

Same name and namespace in other branches
  1. 8 modules/leaflet_views/src/Plugin/views/style/MarkerDefault.php \Drupal\leaflet_views\Plugin\views\style\MarkerDefault::renderGroupingSets()
  2. 2.1.x modules/leaflet_views/src/Plugin/views/style/MarkerDefault.php \Drupal\leaflet_views\Plugin\views\style\MarkerDefault::renderGroupingSets()

Render the grouping sets.

Plugins may override this method if they wish some other way of handling grouping.

Parameters

$sets: An array keyed by group content containing the grouping sets to render. Each set contains the following associative array:

  • group: The group content.
  • level: The hierarchical level of the grouping.
  • rows: The result rows to be rendered in this group..

Return value

array Render array of grouping sets.

Overrides StylePluginBase::renderGroupingSets

File

modules/leaflet_views/src/Plugin/views/style/MarkerDefault.php, line 102

Class

MarkerDefault
Style plugin to render leaflet markers.

Namespace

Drupal\leaflet_views\Plugin\views\style

Code

public function renderGroupingSets($sets, $level = 0) {
  $output = [];
  foreach ($sets as $set) {
    if ($this
      ->usesRowPlugin()) {
      foreach ($set['rows'] as $index => $row) {
        $this->view->row_index = $index;
        $set['rows'][$index] = $this->view->rowPlugin
          ->render($row);
        $this
          ->alterLeafletMarkerPoints($set['rows'][$index], $row);
        if (!$set['rows'][$index]) {
          unset($set['rows'][$index]);
        }
      }
    }
    $set['features'] = [];
    foreach ($set['rows'] as $group) {
      $set['features'] = array_merge($set['features'], $group);
    }

    // Abort if we haven't managed to build any features.
    if (empty($set['features'])) {
      continue;
    }
    if ($feature_group = $this
      ->renderLeafletGroup($set['group'], $level, $set['features'])) {

      // Allow modules to adjust the feature group.
      $this->moduleHandler
        ->alter('leaflet_views_feature_group', $feature_group, $this);

      // If the rendered "feature group" is actually only a list of features,
      // merge them into the output; else simply append the feature group.
      if (empty($feature_group['group'])) {
        $output = array_merge($output, $feature_group['features']);
      }
      else {
        $output[] = $feature_group;
      }
    }
  }
  unset($this->view->row_index);
  return $output;
}