class IpGeoLocPluginStyleMap in IP Geolocation Views & Maps 8
Same name in this branch
- 8 src/Plugin/views/argument/IpGeoLocPluginArgDefaultIPGeoLoc.php \Drupal\ip_geoloc\Plugin\views\argument\IpGeoLocPluginStyleMap
- 8 src/Plugin/views/style/IpGeoLocPluginStyleMap.php \Drupal\ip_geoloc\Plugin\views\style\IpGeoLocPluginStyleMap
Views Style plugin extension for Map.
Plugin annotation
@ViewsStyle(
id = "ip_geoloc_plugin_style",
title = @Translation("Map (Google API, via IPGV&M)"),
help = @Translation("Views Style plugin extension for Map."),
theme = "ip_geoloc_map",
display_types = { "normal" }
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\views\Plugin\views\PluginBase implements DependentPluginInterface, ContainerFactoryPluginInterface, TrustedCallbackInterface, ViewsPluginInterface
- class \Drupal\views\Plugin\views\style\StylePluginBase
- class \Drupal\ip_geoloc\Plugin\views\style\IpGeoLocPluginStyleMap
- class \Drupal\views\Plugin\views\style\StylePluginBase
- class \Drupal\views\Plugin\views\PluginBase implements DependentPluginInterface, ContainerFactoryPluginInterface, TrustedCallbackInterface, ViewsPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of IpGeoLocPluginStyleMap
1 string reference to 'IpGeoLocPluginStyleMap'
- ip_geoloc_views_pre_render in ./
ip_geoloc.module - Implements hook_views_pre_render().
File
- src/
Plugin/ views/ style/ IpGeoLocPluginStyleMap.php, line 34
Namespace
Drupal\ip_geoloc\Plugin\views\styleView source
class IpGeoLocPluginStyleMap extends StylePluginBase {
/**
* {@inheritdoc}
*/
protected $usesGrouping = TRUE;
/**
* {@inheritdoc}
*/
protected $usesFields = TRUE;
/**
* Plugin base constructor for dependency injection.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, IpGeoLocAPI $api, ModuleHandler $module_handler, IpGeoLocGlobal $ip_geoloc_global, TranslationManager $string_translation, IpGeoLocSession $ip_geoloc_session, IpGeoLocViewsPluginStyle $ip_geoloc_view_plugin_style, RequestStack $request_stack) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->api = $api;
$this->module_handler = $module_handler;
$this->ip_geoloc_global = $ip_geoloc_global;
$this->string_translation = $string_translation;
$this->session = $ip_geoloc_session;
$this->view_plugin_style = $ip_geoloc_view_plugin_style;
$this->request_stack = $request_stack;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('ip_geoloc.api'), $container
->get('module_handler'), $container
->get('ip_geoloc.global'), $container
->get('string_translation'), $container
->get('ip_geoloc.session'), $container
->get('ip_geoloc.views_plugin_style'), $container
->get('request_stack'));
}
/**
* Set default Leaflet options.
*/
protected function defineOptions() {
$options = parent::defineOptions();
$latitude = $this->module_handler
->moduleExists('location') ? 'location_latitude' : 'ip_geoloc_latitude';
// For field-based modules.
$longitude = $this->module_handler
->moduleExists('location') ? 'location_longitude' : ($latitude == 'ip_geoloc_latitude' ? 'ip_geoloc_longitude' : $latitude);
$options['ip_geoloc_views_plugin_latitude'] = [
'default' => $latitude,
];
$options['ip_geoloc_views_plugin_longitude'] = [
'default' => $longitude,
];
$options['differentiator'] = [
'contains' => [
'differentiator_field' => [
'default' => '',
],
],
];
$options['default_marker_color'] = [
'default' => '<none>',
];
$options['center_option'] = [
'default' => IP_GEOLOC_MAP_CENTER_ON_FIRST_LOCATION,
];
$options['visitor_marker'] = [
'default' => '<none>',
];
$options['gps_roles'] = [
'default' => [
DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID,
DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID,
],
];
$options['map_options'] = [
'default' => '',
];
$options['map_div_style'] = [
'default' => '',
];
$options['empty_map_center'] = [
'default' => '',
];
return $options;
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form_state
->set('renderer', 'google');
$this->view_plugin_style
->pluginStyleBulkOfForm($this, $form, $form_state);
//ip_geoloc_plugin_style_bulk_of_form($this, $form, $form_state);
$form['map_options'] = [
'#title' => t('Map options'),
'#type' => 'textfield',
'#size' => 127,
'#maxlength' => 511,
'#default_value' => $this->options['map_options'],
'#description' => t("If left blank, the default ") . IP_GEOLOC_RECENT_VISITORS_MAP_OPTIONS . t(" will produce a world map zoomed in to level 2. A list of map options can be found <a href='") . IP_GEOLOC_DOC_GOOGLE_MAP_OPTIONS . t("'>here</a>. Remember to separate options with comma's, not semi-colons, and make sure your (double) quotes match.<br/>These options apply a grey hue to all roads:<br/>") . IP_GEOLOC_EXAMPLE_MAP_OPTIONS,
'#weight' => 35,
];
$form['default_marker_color'] = [
'#title' => t('Marker color'),
'#type' => 'textfield',
'#size' => 127,
'#maxlength' => 511,
'#default_value' => $this->options['default_marker_color'],
'#description' => t("Add the default marker color, by default google maps style. The available values are: blue,drupal,green,grey,light-blue,orange,pink,purple,red,red-cluster,red+dot,red+square,white,yellow.png"),
'#weight' => 36,
];
$form['map_div_style'] = [
'#title' => t('Map style (CSS attributes)'),
'#type' => 'textfield',
'#size' => 127,
'#maxlength' => 511,
'#default_value' => $this->options['map_div_style'],
'#description' => t('If left blank, the default ') . IP_GEOLOC_MAP_DIV_DEFAULT_STYLE . t(' will result in a map of 300 pixels high, with a width bounded by the element that contains it. Separate style settings with semi-colons. Do not enter quotes or equal signs.'),
'#weight' => 37,
];
$form['visitor_marker'] = [
'#title' => t('Visitor marker color'),
'#type' => 'textfield',
'#size' => 6,
'#default_value' => $this->options['visitor_marker'],
'#description' => t("Show visitor marker in the color specified. %color_code is bright green. Note that an additional web service call will be made to retrieve the marker image, unless this field is left blank, which will result in a standard red marker. Enter <em><none></em> if you do not wish to display the visitor's current location.", [
'%color_code' => '00FF00',
]),
'#weight' => 90,
];
$form['gps_roles'] = [
'#title' => t('Roles for which HTML5-style visitor location retrieval is to be applied'),
'#type' => 'checkboxes',
'#default_value' => $this->options['gps_roles'],
'#options' => user_role_names(),
'#description' => t('This is subject to the visitor willing to share their location when prompted by their browser. If they decline, or if their roles aren\'t ticked, an IP address lookup will be attempted instead. In case the lookup fails, for instance because you have not enabled Smart IP or GeoIP, make sure you specify "centerLat" and "centerLng" in the <strong>Map options</strong> below to avoid an empty canvas.'),
'#weight' => 95,
];
return $form;
}
/**
* Validate the options form.
*/
public function validateOptionsForm(&$form, FormStateInterface $form_state) {
$this->view_plugin_style
->pluginStyleBulkOfFormValidate($form, $form_state);
}
/**
* Transform the View result in a list of markers and render these on a map.
*/
public function render() {
if (!empty($this->view->live_preview)) {
return t('The preview function is incompatible with Google Maps so cannot be used. Please visit the page path or block to view your map.');
}
$this->view_plugin_style
->pluginStyleRenderFields($this);
$locations = $this->view_plugin_style
->pluginStyleExtractLocations($this);
$map_options = empty($this->options['map_options']) ? IP_GEOLOC_RECENT_VISITORS_MAP_OPTIONS : $this->options['map_options'];
$map_div_style = empty($this->options['map_div_style']) ? IP_GEOLOC_MAP_DIV_DEFAULT_STYLE : SafeMarkup::checkPlain($this->options['map_div_style']);
$marker_color = empty($this->options['default_marker_color']) ? '' : $this->options['default_marker_color'];
if (empty($this->options['visitor_marker'])) {
// Default to standard red marker.
$visitor_marker = TRUE;
}
else {
$visitor_marker = trim($this->options['visitor_marker']);
$visitor_marker = strpos($visitor_marker, 'none') === FALSE ? SafeMarkup::checkPlain($visitor_marker) : FALSE;
}
$center_option = !isset($this->options['center_option']) ? IP_GEOLOC_MAP_CENTER_ON_FIRST_LOCATION : $this->options['center_option'];
$center_latlng = [];
if ($visitor_marker || $center_option == IP_GEOLOC_MAP_CENTER_ON_VISITOR) {
// Perform database IP lookup as backup/replacement for HTML5 location
// Visitor may be moving so ignore existing lat/long.
$resample = TRUE;
// Do not store lat/long and city as it will obliterate the
// reverse-geocoded one.
$store = FALSE;
// We only need lat/long, not full street address.
$reverse_geocode = FALSE;
$visitor_location = $this->api
->getLocationByIp($this->request_stack
->getCurrentRequest()
->getClientIp(), $resample, $store, $reverse_geocode);
if (isset($visitor_location['latitude']) && isset($visitor_location['longitude'])) {
$center_latlng = [
$visitor_location['latitude'],
$visitor_location['longitude'],
];
}
}
if (empty($locations)) {
$ll = trim($this->options['empty_map_center']);
if (empty($ll)) {
// No map whatsoever.
return;
}
if ($ll != t('visitor')) {
// Empty map centered on coordinates provided.
list($center_lat, $center_lng) = preg_split("/[\\s,]+/", $ll);
}
}
elseif ($center_option == IP_GEOLOC_MAP_CENTER_OF_LOCATIONS || $center_option == IP_GEOLOC_MAP_CENTER_OF_LOCATIONS_WEIGHTED) {
list($center_lat, $center_lng) = $this->api
->centerOfLocations($locations, $center_option == IP_GEOLOC_MAP_CENTER_OF_LOCATIONS_WEIGHTED);
}
if (isset($center_lat) && isset($center_lng)) {
$map_options = Unicode::substr($map_options, 0, strrpos($map_options, '}'));
$map_options = $map_options . ', "centerLat":' . $center_lat . ', "centerLng":' . $center_lng . '}';
}
$account = \Drupal::currentUser();
$gps_roles = empty($this->options['gps_roles']) ? [
DRUPAL_ANONYMOUS_RID,
DRUPAL_AUTHENTICATED_RID,
] : $this->options['gps_roles'];
$gps_roles_applicable = array_intersect($gps_roles, array_keys($account->roles));
// drupal_add_js(IP_GEOLOC_GOOGLE_MAPS, ['type' => 'external', 'group' => JS_LIBRARY]);
// drupal_add_js(drupal_get_path('module', 'ip_geoloc') . '/js/ip_geoloc_gmap_multi_visitor.js');
if (!isset($map_options)) {
$map_options = IP_GEOLOC_RECENT_VISITORS_MAP_OPTIONS;
}
$div_id = 'ip-geoloc-map-of-view-' . $this->view->storage
->id() . '-' . $this->view->current_display;
return $this->api
->outputMapMultiLocation($locations, $div_id, $map_options, $map_div_style, $marker_color, $visitor_marker, $center_option, $center_latlng, !empty($gps_roles_applicable));
}
/**
* Sets rendered field definition.
*/
public function setRenderedFields($rendered_fields = []) {
$this->rendered_fields = $rendered_fields;
}
/**
* Gets rendered field definition.
*/
public function getRenderedFields() {
return $this->rendered_fields;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
IpGeoLocPluginStyleMap:: |
protected | property |
Does the style plugin for itself support to add fields to its output. Overrides StylePluginBase:: |
|
IpGeoLocPluginStyleMap:: |
protected | property |
Does the style plugin support grouping of rows. Overrides StylePluginBase:: |
|
IpGeoLocPluginStyleMap:: |
public | function |
Provide a form to edit options for this plugin. Overrides StylePluginBase:: |
|
IpGeoLocPluginStyleMap:: |
public static | function |
Creates an instance of the plugin. Overrides PluginBase:: |
|
IpGeoLocPluginStyleMap:: |
protected | function |
Set default Leaflet options. Overrides StylePluginBase:: |
|
IpGeoLocPluginStyleMap:: |
public | function | Gets rendered field definition. | |
IpGeoLocPluginStyleMap:: |
public | function |
Transform the View result in a list of markers and render these on a map. Overrides StylePluginBase:: |
|
IpGeoLocPluginStyleMap:: |
public | function | Sets rendered field definition. | |
IpGeoLocPluginStyleMap:: |
public | function |
Validate the options form. Overrides StylePluginBase:: |
|
IpGeoLocPluginStyleMap:: |
public | function |
Plugin base constructor for dependency injection. Overrides PluginBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
public | property | Plugins's definition | |
PluginBase:: |
public | property | The display object this plugin is for. | |
PluginBase:: |
public | property | Options for this plugin will be held here. | |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
protected | property | Stores the render API renderer. | 3 |
PluginBase:: |
public | property | The top object of a view. | 1 |
PluginBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
14 |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
protected | function | Do the work to filter out stored options depending on the defined options. | |
PluginBase:: |
public | function |
Filter out stored options depending on the defined options. Overrides ViewsPluginInterface:: |
|
PluginBase:: |
public | function |
Returns an array of available token replacements. Overrides ViewsPluginInterface:: |
|
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function |
Returns the plugin provider. Overrides ViewsPluginInterface:: |
|
PluginBase:: |
protected | function | Returns the render API renderer. | 1 |
PluginBase:: |
public | function |
Adds elements for available core tokens to a form. Overrides ViewsPluginInterface:: |
|
PluginBase:: |
public | function |
Returns a string with any core tokens replaced. Overrides ViewsPluginInterface:: |
|
PluginBase:: |
constant | Include entity row languages when listing languages. | ||
PluginBase:: |
constant | Include negotiated languages when listing languages. | ||
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
protected | function | Makes an array of languages, optionally including special languages. | |
PluginBase:: |
public | function |
Return the human readable name of the display. Overrides ViewsPluginInterface:: |
|
PluginBase:: |
public static | function |
Moves form elements into fieldsets for presentation purposes. Overrides ViewsPluginInterface:: |
|
PluginBase:: |
public static | function |
Flattens the structure of form elements. Overrides ViewsPluginInterface:: |
|
PluginBase:: |
public static | function | Returns substitutions for Views queries for languages. | |
PluginBase:: |
protected | function | Fills up the options of the plugin with defaults. | |
PluginBase:: |
public | function |
Handle any special handling on the validate form. Overrides ViewsPluginInterface:: |
16 |
PluginBase:: |
public | function |
Returns the summary of the settings in the display. Overrides ViewsPluginInterface:: |
6 |
PluginBase:: |
public | function |
Provide a full list of possible theme templates used by this style. Overrides ViewsPluginInterface:: |
1 |
PluginBase:: |
public | function |
Unpack options over our existing defaults, drilling down into arrays
so that defaults don't get totally blown away. Overrides ViewsPluginInterface:: |
|
PluginBase:: |
public | function |
Returns the usesOptions property. Overrides ViewsPluginInterface:: |
8 |
PluginBase:: |
protected | function | Replaces Views' tokens in a given string. The resulting string will be sanitized with Xss::filterAdmin. | 1 |
PluginBase:: |
constant | Query string to indicate the site default language. | ||
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
StylePluginBase:: |
protected | property | Should field labels be enabled by default. | 1 |
StylePluginBase:: |
protected | property | The theme function used to render the grouping set. | |
StylePluginBase:: |
protected | property | Stores the rendered field values, keyed by the row index and field name. | |
StylePluginBase:: |
protected | property | Store all available tokens row rows. | |
StylePluginBase:: |
protected | property |
Denotes whether the plugin has an additional options form. Overrides PluginBase:: |
|
StylePluginBase:: |
protected | property | Does the style plugin support custom css class for the rows. | 3 |
StylePluginBase:: |
protected | property | Whether or not this style uses a row plugin. | 10 |
StylePluginBase:: |
public | function | Called by the view builder to see if this style handler wants to interfere with the sorts. If so it should build; if it returns any non-TRUE value, normal sorting will NOT be added to the query. | 1 |
StylePluginBase:: |
public | function | Called by the view builder to let the style build a second set of sorts that will come after any other sorts in the view. | 1 |
StylePluginBase:: |
public | function | Return TRUE if this style enables field labels by default. | 1 |
StylePluginBase:: |
public | function |
Clears a plugin. Overrides PluginBase:: |
|
StylePluginBase:: |
public | function | #pre_render callback for view row field rendering. | |
StylePluginBase:: |
public | function | Should the output of the style plugin be rendered even if it's a empty view. | 2 |
StylePluginBase:: |
public | function | Gets a rendered field. | |
StylePluginBase:: |
public | function | Get the raw field value. | |
StylePluginBase:: |
public | function | Return the token replaced row class for the specified row. | |
StylePluginBase:: |
public | function |
Overrides \Drupal\views\Plugin\views\PluginBase::init(). Overrides PluginBase:: |
|
StylePluginBase:: |
public | function | Allow the style to do stuff before each row is rendered. | |
StylePluginBase:: |
public | function |
Add anything to the query that we might need to. Overrides PluginBase:: |
1 |
StylePluginBase:: |
protected | function | Renders all of the fields for a given style and store them on the object. | |
StylePluginBase:: |
public | function | Group records as needed for rendering. | |
StylePluginBase:: |
public | function | Render the grouping sets. | |
StylePluginBase:: |
protected | function | Renders a group of rows of the grouped view. | |
StylePluginBase:: |
public | function | Take a value and apply token replacement logic to it. | |
StylePluginBase:: |
public static | function |
Lists the trusted callbacks provided by the implementing class. Overrides PluginBase:: |
|
StylePluginBase:: |
public | function | Return TRUE if this style also uses fields. | 3 |
StylePluginBase:: |
public | function | Returns the usesGrouping property. | 3 |
StylePluginBase:: |
public | function | Returns the usesRowClass property. | 3 |
StylePluginBase:: |
public | function | Returns the usesRowPlugin property. | 10 |
StylePluginBase:: |
public | function | Return TRUE if this style uses tokens. | |
StylePluginBase:: |
public | function |
Validate that the plugin is correct and can be saved. Overrides PluginBase:: |
|
StylePluginBase:: |
public | function | Provide a form in the views wizard if this style is selected. | |
StylePluginBase:: |
public | function | Alter the options of a display before they are added to the view. | 1 |
TrustedCallbackInterface:: |
constant | Untrusted callbacks throw exceptions. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger silenced E_USER_DEPRECATION errors. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger E_USER_WARNING errors. |