LeafletAttachment.php in Leaflet 2.0.x
File
modules/leaflet_views/src/Plugin/views/display/LeafletAttachment.php
View source
<?php
namespace Drupal\leaflet_views\Plugin\views\display;
use Drupal\views\Plugin\views\display\Attachment;
use Drupal\views\ViewExecutable;
class LeafletAttachment extends Attachment {
protected $usesPager = FALSE;
protected $usesMore = FALSE;
protected $usesAreas = FALSE;
public function usesLinkDisplay() {
return FALSE;
}
public function attachTo(ViewExecutable $view, $display_id, array &$build) {
$displays = $this
->getOption('displays');
if (empty($displays[$display_id])) {
return;
}
if (!$this
->access()) {
return;
}
$args = $this
->getOption('inherit_arguments') ? $this->view->args : [];
$view
->setArguments($args);
$view
->setDisplay($this->display['id']);
if ($this
->getOption('inherit_pager')) {
$view->display_handler->usesPager = $this->view->displayHandlers
->get($display_id)
->usesPager();
$view->display_handler
->setOption('pager', $this->view->displayHandlers
->get($display_id)
->getOption('pager'));
}
if ($render = $view
->render()) {
$this->view->attachment_before[] = $render + [
'#leaflet-attachment' => TRUE,
];
}
}
public function render() {
$rows = !empty($this->view->result) || $this->view->style_plugin
->evenEmpty() ? $this->view->style_plugin
->render($this->view->result) : [];
$element = [
'#markup' => print_r($rows, TRUE),
'#prefix' => '<pre>',
'#suffix' => '</pre>',
'#attached' => &$this->view->element['#attached'],
'rows' => $rows,
];
return $element;
}
public function getType() {
return 'leaflet';
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['style']['contains']['type']['default'] = 'leaflet_marker_default';
$options['defaults']['default']['style'] = FALSE;
$options['row']['contains']['type']['default'] = 'leaflet_marker';
$options['defaults']['default']['row'] = FALSE;
return $options;
}
}
Classes
Name |
Description |
LeafletAttachment |
Plugin attachment of additional leaflet features to leaflet map views. |