You are here

protected function GeolocationStyleBase::getLocationsFromRow in Geolocation Field 8.3

Render array from views result row.

Parameters

\Drupal\views\ResultRow $row: Result row.

Return value

array List of location render elements.

2 calls to GeolocationStyleBase::getLocationsFromRow()
CommonMap::render in src/Plugin/views/style/CommonMap.php
Render the display in this style.
Layer::render in src/Plugin/views/style/Layer.php
Render the display in this style.

File

src/Plugin/views/style/GeolocationStyleBase.php, line 94

Class

GeolocationStyleBase
Geolocation Style Base.

Namespace

Drupal\geolocation\Plugin\views\style

Code

protected function getLocationsFromRow(ResultRow $row) {
  $locations = [];
  $icon_url = NULL;
  if (!empty($this->options['icon_field']) && $this->options['icon_field'] != 'none') {

    /** @var \Drupal\views\Plugin\views\field\Field $icon_field_handler */
    $icon_field_handler = $this->view->field[$this->options['icon_field']];
    if (!empty($icon_field_handler)) {
      $image_items = $icon_field_handler
        ->getItems($row);
      if (!empty($image_items[0]['rendered']['#item']->entity)) {
        $file_uri = $image_items[0]['rendered']['#item']->entity
          ->getFileUri();
        $style = NULL;
        if (!empty($image_items[0]['rendered']['#image_style'])) {

          /** @var \Drupal\image\Entity\ImageStyle $style */
          $style = ImageStyle::load($image_items[0]['rendered']['#image_style']);
        }
        if (!empty($style)) {
          $icon_url = file_url_transform_relative($style
            ->buildUrl($file_uri));
        }
        else {
          $icon_url = file_url_transform_relative(file_create_url($file_uri));
        }
      }
    }
  }
  elseif (!empty($this->options['marker_icon_path'])) {
    $icon_token_uri = $this
      ->viewsTokenReplace($this->options['marker_icon_path'], $this->rowTokens[$row->index]);
    $icon_token_uri = preg_replace('/\\s+/', '', $icon_token_uri);
    $icon_url = file_url_transform_relative(file_create_url($icon_token_uri));
  }
  try {
    $data_provider = $this->dataProviderManager
      ->createInstance($this->options['data_provider_id'], $this->options['data_provider_settings']);
  } catch (\Exception $e) {
    \Drupal::logger('geolocation')
      ->critical('View with non-existing data provider called.');
    return [];
  }
  foreach ($data_provider
    ->getPositionsFromViewsRow($row, $this->view->field[$this->options['geolocation_field']]) as $position) {
    $location = [
      '#type' => 'geolocation_map_location',
      'content' => $this->view->rowPlugin
        ->render($row),
      '#title' => $this
        ->getTitleField($row) ?? '',
      '#label' => $this
        ->getLabelField($row) ?? '',
      '#coordinates' => $position,
      '#weight' => $row->index,
      '#attributes' => [
        'data-views-row-index' => $row->index,
      ],
    ];
    if (!empty($icon_url)) {
      $location['#icon'] = $icon_url;
    }
    if (!empty($location_id)) {
      $location['#id'] = $location_id;
    }
    if ($this->options['marker_row_number']) {
      $markerOffset = $this->view->pager
        ->getCurrentPage() * $this->view->pager
        ->getItemsPerPage();
      $marker_row_number = (int) $markerOffset + (int) $row->index + 1;
      if (empty($location['#label'])) {
        $location['#label'] = $marker_row_number;
      }
      else {
        $location['#label'] = $location['#label'] . ': ' . $location['#label'];
      }
    }
    $locations[] = $location;
  }
  $locations = array_merge($data_provider
    ->getLocationsFromViewsRow($row, $this->view->field[$this->options['geolocation_field']]), $locations);
  $locations = array_merge($data_provider
    ->getShapesFromViewsRow($row, $this->view->field[$this->options['geolocation_field']]), $locations);
  return $locations;
}