protected function CommonMapBase::getLocationsFromRow in Geolocation Field 8.2
Render array from views result row.
Parameters
\Drupal\views\ResultRow $row: Result row.
Return value
array List of location render elements.
1 call to CommonMapBase::getLocationsFromRow()
- CommonMapBase::render in src/
Plugin/ views/ style/ CommonMapBase.php - Render the display in this style.
File
- src/
Plugin/ views/ style/ CommonMapBase.php, line 240
Class
- CommonMapBase
- Allow to display several field items on a common map.
Namespace
Drupal\geolocation\Plugin\views\styleCode
protected function getLocationsFromRow(ResultRow $row) {
$locations = [];
if (!empty($this->titleField)) {
if (!empty($this->rendered_fields[$row->index][$this->titleField])) {
$title_build = $this->rendered_fields[$row->index][$this->titleField];
}
elseif (!empty($this->view->field[$this->titleField])) {
$title_build = $this->view->field[$this->titleField]
->render($row);
}
}
$icon_url = NULL;
if (!empty($this->iconField)) {
/** @var \Drupal\views\Plugin\views\field\Field $icon_field_handler */
$icon_field_handler = $this->view->field[$this->iconField];
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));
}
$data_provider = $this->dataProviderManager
->createInstance($this->options['data_provider_id'], $this->options['data_provider_settings']);
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' => empty($title_build) ? '' : $title_build,
'#position' => $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();
$location['#label'] = (int) $markerOffset + (int) $row->index + 1;
}
$locations[] = $location;
}
return $locations;
}