Skip to content

Commit

Permalink
Fix coding standards (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
indigoxela authored Apr 7, 2023
1 parent 44bf756 commit 7161ddb
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 60 deletions.
5 changes: 2 additions & 3 deletions leaflet.api.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* @file
* API documentation for Administration menu.
Expand Down Expand Up @@ -63,7 +62,7 @@ function hook_leaflet_map_info() {
),
),
),
// Uncomment the lines below to use a custom icon
// Uncomment the lines below to use a custom icon.
// @code
// 'icon' => array(
// 'iconUrl' => '/sites/default/files/icon.png',
Expand Down Expand Up @@ -91,7 +90,7 @@ function hook_leaflet_map_info() {
* @see leaflet_map_get_info()
* @see hook_leaflet_map_info()
*/
function hook_leaflet_map_prebuild_alter(&$settings) {
function hook_leaflet_map_prebuild_alter(array &$settings) {
$settings['mapId'] = 'my-map-id';
$settings['features']['icon'] = 'my-icon-url';
}
61 changes: 37 additions & 24 deletions leaflet.formatters.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* @file
* Leaflet field formatter functions.
Expand Down Expand Up @@ -109,12 +108,22 @@ function leaflet_field_formatter_settings_form($field, $instance, $view_mode, $f
}
}
$fieldpath = 'fields[' . $field['field_name'] . '][settings_edit_form][settings]';
$element['popup'] = leaflet_form_elements('popup', $settings, array('path' => $fieldpath));
$element['popup'] = leaflet_form_elements('popup', $settings, array(
'path' => $fieldpath,
));
$element['zoom'] = leaflet_form_elements('zoom', $settings);
$element['icon'] = leaflet_form_elements('icon', $settings, array('path' => $fieldpath, 'fields' => $field_options));
$element['vector_display'] = leaflet_form_elements('vector_display', $settings, array('path' => $fieldpath));
$element['icon'] = leaflet_form_elements('icon', $settings, array(
'path' => $fieldpath,
'fields' => $field_options,
));
$element['vector_display'] = leaflet_form_elements('vector_display', $settings, array(
'path' => $fieldpath,
));
// Show the list of available tokens.
$element['tokens'] = leaflet_form_elements('tokens', $settings, array('weight' => 999, 'entity_type' => $entity_type));
$element['tokens'] = leaflet_form_elements('tokens', $settings, array(
'weight' => 999,
'entity_type' => $entity_type,
));
}

return $element;
Expand Down Expand Up @@ -169,7 +178,10 @@ function leaflet_field_formatter_view($entity_type, $entity, $field, $instance,
}

// Let other modules add/customize settings.
$entity_wrapper = array('entity_type' => $entity_type, 'entity' => $entity);
$entity_wrapper = array(
'entity_type' => $entity_type,
'entity' => $entity,
);
backdrop_alter('leaflet_map_settings', $map, $features, $settings, $entity_wrapper);

leaflet_apply_map_settings($map, $features, $settings, $entity_type);
Expand All @@ -189,9 +201,9 @@ function leaflet_field_formatter_view($entity_type, $entity, $field, $instance,
*
* @return array
* Points built for consumption by the leaflet module as expected by
* leaflet_render_map().
* leaflet_render_map().
*/
function leaflet_process_geofield($items = array()) {
function leaflet_process_geofield(array $items = array()) {
$data = array();

// This is a geofield formatter, so we load the class from there. Needed for
Expand Down Expand Up @@ -365,7 +377,7 @@ function leaflet_process_geofield($items = array()) {
* @param string $entity_type
* Entity type this map is being displayed for.
*/
function leaflet_apply_map_settings(&$map, &$features, $map_settings, $entity_type) {
function leaflet_apply_map_settings(array &$map, array &$features, array $map_settings, $entity_type) {
// These are the settings key that will be tokenized by entity:
$token_by_entity = array(
'popup',
Expand Down Expand Up @@ -410,7 +422,9 @@ function leaflet_apply_map_settings(&$map, &$features, $map_settings, $entity_ty
// Apply tokens where relevant:
$settings = $map_settings;
$entity = !empty($feat['entity']) ? $feat['entity'] : NULL;
$token_args = array('data' => array($entity_type => $entity), 'options' => array('clear' => TRUE));
$token_args = array('data' => array($entity_type => $entity), 'options' => array(
'clear' => TRUE,
));
foreach ($token_by_entity as $key) {
if (isset($settings[$key]) && is_array($settings[$key])) {
array_walk_recursive($settings[$key], 'leaflet_token_replace', $token_args);
Expand Down Expand Up @@ -500,19 +514,18 @@ function leaflet_token_replace(&$subject, $key, $data = array()) {

/**
* Helper function to standardize forms between views and field formatters.
*
* $group - String
* The name of the group element to generate.
*
* $settings - Array
* Current form settings (for defaults, etc)
*
* $options - Array
* Special options needed for this form element, if necessary.
*
* Return - A fully loaded form element.
*
* @param string $group
* The name of the group element to generate.
* @param array $settings
* Current form settings (for defaults, etc)
* @param array|null $options
* Special options needed for this form element, if necessary.
*
* @return array
* A fully loaded form element.
*/
function leaflet_form_elements($group, $settings, $options = NULL) {
function leaflet_form_elements($group, array $settings, $options = NULL) {
$form_element = NULL;
switch ($group) {
case 'popup':
Expand Down Expand Up @@ -655,7 +668,7 @@ function leaflet_form_elements($group, $settings, $options = NULL) {
'#type' => 'select',
'#title' => t('Marker field'),
'#description' => t('Field to use as output for a map marker.'),
// See [#1796656]
// See [#1796656].
'#options' => (array) array_merge(array('' => ''), $options['fields']),
'#default_value' => isset($settings[$group]['html']) ? $settings[$group]['html'] : '',
'#empty_option' => t('-- Select --'),
Expand Down Expand Up @@ -929,7 +942,7 @@ function leaflet_form_elements($group, $settings, $options = NULL) {
break;

case "tokens":
// See [#2176681]
// See [#2176681].
$form_element = array(
'#type' => 'container',
'#theme' => 'token_tree_link',
Expand Down
10 changes: 5 additions & 5 deletions leaflet.module
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function leaflet_library_info() {
* Attach Leaflet-required client files and return renderable array for a map.
*
* @param array $map
* Map definition as returned my leaflet_map_get_info();
* Map definition as returned my leaflet_map_get_info().
* @param array $features
* Associative array of map features.
* @param string $height
Expand All @@ -109,7 +109,7 @@ function leaflet_library_info() {
* @return array
* A renderable array.
*/
function leaflet_build_map($map, $features = array(), $height = '400px') {
function leaflet_build_map(array $map, array $features = array(), $height = '400px') {
$map_id = backdrop_html_id('leaflet_map');
$build = array(
'#theme' => 'head_tag',
Expand Down Expand Up @@ -151,7 +151,7 @@ function leaflet_build_map($map, $features = array(), $height = '400px') {
// Load the leaflet library, which includes integration files.
$build['#attached']['library'][] = array('leaflet', 'leaflet');

// Let other modules properly attach libraries as well [#2567387]
// Let other modules properly attach libraries as well [#2567387].
backdrop_alter('leaflet_build_map', $build);

return $build;
Expand All @@ -163,7 +163,7 @@ function leaflet_build_map($map, $features = array(), $height = '400px') {
* Load all Leaflet required client files and return markup for a map.
*
* @param array $map
* Map definition as returned my leaflet_map_get_info();
* Map definition as returned my leaflet_map_get_info().
* @param array $features
* Associative array of map features.
* @param string $height
Expand All @@ -172,7 +172,7 @@ function leaflet_build_map($map, $features = array(), $height = '400px') {
* @return string
* map markup
*/
function leaflet_render_map($map, $features = array(), $height = '400px') {
function leaflet_render_map(array $map, array $features = array(), $height = '400px') {
$build = leaflet_build_map($map, $features, $height);
return render($build);
}
Expand Down
9 changes: 4 additions & 5 deletions modules/leaflet_demo/leaflet_demo.module
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ function leaflet_demo_map_parameters_form_submit($form, &$form_state) {
* Outputs the HTML for all available Leaflet maps, centered on supplied coords.
*
* @param string $latitude
* the latitude
* The latitude.
* @param string $longitude
* the longitude
* The longitude.
*
* @return string
* the map string as rendered html
* The map string as rendered html.
*/
function leaflet_demo_output_maps($latitude = LEAFLET_DEMO_DEFAULT_LAT, $longitude = LEAFLET_DEMO_DEFAULT_LNG, $zoom = LEAFLET_DEMO_DEFAULT_ZOOM) {

Expand All @@ -172,8 +172,7 @@ function leaflet_demo_output_maps($latitude = LEAFLET_DEMO_DEFAULT_LAT, $longitu
$features[0]['leaflet_id'] = "demo-$map_id";
$title = $map_info[$map_id]['label'];
$built_map = leaflet_build_map($map, $features, '300px');
$output .=
'<div class="leaflet-gallery-map">'
$output .= '<div class="leaflet-gallery-map">'
. "<div>$title</div>"
. render($built_map)
. '</div>';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* @file
* API documentation for Leaflet Markercluster.
Expand Down
5 changes: 4 additions & 1 deletion modules/leaflet_markercluster/leaflet_markercluster.module
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ function leaflet_markercluster_leaflet_build_map_alter(&$build) {
}
}
if (!isset($settings['map']['settings']['maxClusterRadius']) || $settings['map']['settings']['maxClusterRadius'] > 0) {
$build['#attached']['library'][] = array('leaflet_markercluster', 'leaflet_markercluster');
$build['#attached']['library'][] = array(
'leaflet_markercluster',
'leaflet_markercluster',
);
$build['#attached']['js'][] = array(
'data' => backdrop_get_path('module', 'leaflet_markercluster') . '/js/leaflet_markercluster.backdrop.js',
'weight' => 1,
Expand Down
2 changes: 0 additions & 2 deletions modules/leaflet_more_maps/leaflet_more_maps.admin.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* @file
* Menu callback for Leaflet More Maps admin configuration.
Expand Down Expand Up @@ -120,7 +119,6 @@ function leaflet_more_maps_admin_configure_form_submit($form, &$form_state) {
$config = config('leaflet_more_maps.settings');

// form_state_values_clean($form_state);

$config->set('google_satellite_version', $form_state['values']['google_satellite_version']);
$config->set('thunderforest_api_key', $form_state['values']['thunderforest_api_key']);
$config->set('mapbox_access_token', $form_state['values']['mapbox_access_token']);
Expand Down
1 change: 0 additions & 1 deletion modules/leaflet_more_maps/leaflet_more_maps.api.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* @file
* API documentation for Leaflet More Maps module.
Expand Down
1 change: 0 additions & 1 deletion modules/leaflet_more_maps/leaflet_more_maps.install
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* @file
* Install and uninstall hooks for Leaflet More Maps module.
Expand Down
11 changes: 6 additions & 5 deletions modules/leaflet_more_maps/leaflet_more_maps.module
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function leaflet_more_maps_default_settings() {
'touchZoom' => TRUE,
'trackResize' => TRUE,
// Don't specify, if you want to use Auto-box.
// @codingStandardsIgnoreLine
// 'zoom' => 2,
'zoomAnimation' => TRUE,
'zoomControl' => TRUE,
Expand All @@ -37,7 +38,7 @@ function leaflet_more_maps_default_settings() {
*/
function leaflet_more_maps_leaflet_map_prebuild_alter(&$variables = NULL) {
$path = backdrop_get_path('module', 'leaflet_more_maps');
// Increase weight so we're included after 'leaflet.drupal.js'
// Increase weight so we're included after 'leaflet.drupal.js'.
$options = array('type' => 'file', 'weight' => 1);
backdrop_add_js("$path/js/leaflet_more_maps.js", $options);
}
Expand Down Expand Up @@ -66,7 +67,7 @@ function leaflet_more_maps_leaflet_map_info_alter(&$map_info) {
* Assemble default map info.
*/
function _leaflet_more_maps_assemble_default_map_info(&$map_info, $default_settings = array()) {
// For most maps, use headless protocol rather than logic based on $is_https;
// For most maps, use headless protocol rather than logic based on $is_https.
$prot = '//';
global $is_https;

Expand Down Expand Up @@ -253,7 +254,7 @@ function _leaflet_more_maps_assemble_default_map_info(&$map_info, $default_setti
'roadmap' => array(
'type' => 'google',
// For retina displays we append '&style=high_dpi&w=512',
// see leaflet_more_maps.js
// see leaflet_more_maps.js.
'urlTemplate' => $prot . 'mt{s}.googleapis.com/vt?x={x}&y={y}&z={z}',
'options' => array(
'attribution' => $attr_google,
Expand All @@ -280,7 +281,7 @@ function _leaflet_more_maps_assemble_default_map_info(&$map_info, $default_setti
// https://docs.mapbox.com/api/maps/styles/
$mapbox_access_token = config_get('leaflet_more_maps.settings', 'mapbox_access_token');
if (empty($mapbox_access_token)) {
// MapBox as used on leafletjs.com
// MapBox as used on leafletjs.com.
$mapbox_access_token = 'pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw';
}
$attr_mapbox = 'Map data &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>';
Expand Down Expand Up @@ -312,7 +313,7 @@ function _leaflet_more_maps_assemble_default_map_info(&$map_info, $default_setti
);
}

// OpenStreetMap OSM Mapnik classic map is available via leaflet.module
// OpenStreetMap OSM Mapnik classic map is available via leaflet.module.
$attr_osm = 'Map data &copy; <a target="attr" href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors';

$attr_thunderforest = '<a target="attr" href="https://www.thunderforest.com/">ThunderForest</a>. ' . $attr_osm;
Expand Down
1 change: 0 additions & 1 deletion modules/leaflet_views/leaflet_views.api.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* @file
* API documentation for Leaflet views.
Expand Down
1 change: 0 additions & 1 deletion modules/leaflet_views/leaflet_views.install
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* @file
* Install functions for leaflet_views.
Expand Down
1 change: 0 additions & 1 deletion modules/leaflet_views/leaflet_views.module
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* @file
* Hooks implementations for leaflet_views.
Expand Down
1 change: 0 additions & 1 deletion modules/leaflet_views/leaflet_views.views.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* @file
* Leaflet maps views integration.
Expand Down
23 changes: 15 additions & 8 deletions modules/leaflet_views/leaflet_views_plugin_style.inc
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

/**
* @file
* Extension of the Views Plugin Style for Leaflet Map
* Adapted from the GeoField Map views module and the OpenLayers Views module.
*/

/**
* {@inheritdoc}
*/
class leaflet_views_plugin_style extends views_plugin_style {

/**
Expand Down Expand Up @@ -166,9 +168,7 @@ class leaflet_views_plugin_style extends views_plugin_style {
'#default_value' => $this->options['name_field'],
);

$desc_options = array_merge(array(
'' => '',
), $fields);
$desc_options = array_merge(array('' => '',), $fields);

// Add an option to render the entire entity using a view mode.
if (isset($this->entity_type)) {
Expand Down Expand Up @@ -257,9 +257,17 @@ class leaflet_views_plugin_style extends views_plugin_style {
);

$form['zoom'] = leaflet_form_elements('zoom', $this->options);
$form['icon'] = leaflet_form_elements('icon', $this->options, array('path' => 'style_options', 'fields' => $fields));
$form['vector_display'] = leaflet_form_elements('vector_display', $this->options, array('path' => 'style_options'));
$form['tokens'] = leaflet_form_elements('tokens', $this->options, array('weight' => 998, 'entity_type' => $this->entity_type));
$form['icon'] = leaflet_form_elements('icon', $this->options, array(
'path' => 'style_options',
'fields' => $fields,
));
$form['vector_display'] = leaflet_form_elements('vector_display', $this->options, array(
'path' => 'style_options',
));
$form['tokens'] = leaflet_form_elements('tokens', $this->options, array(
'weight' => 998,
'entity_type' => $this->entity_type,
));
}

/**
Expand Down Expand Up @@ -370,7 +378,6 @@ class leaflet_views_plugin_style extends views_plugin_style {
}
return leaflet_build_map($map, $data, $this->options['height'] . 'px');
}
return;
}

/**
Expand Down

0 comments on commit 7161ddb

Please sign in to comment.