3
0
Fork 0
mirror of https://github.com/farmOS/farmOS.git synced 2024-02-23 11:37:38 +01:00

Add a farm_map_build() function, for building farm maps.

This commit is contained in:
Michael Stenta 2018-02-26 11:54:25 -05:00
parent 53455f101f
commit 1006a3054b
4 changed files with 38 additions and 23 deletions

View file

@ -244,11 +244,6 @@ function farm_area_page_build(&$page) {
return;
}
// If dashboard maps are disabled in the farm_map module settings, bail.
if (!variable_get('farm_map_show', TRUE)) {
return;
}
// If this is the farm dashboard, display the areas map.
$current_path = current_path();
$map_paths = array(
@ -259,11 +254,8 @@ function farm_area_page_build(&$page) {
);
if (in_array($current_path, $map_paths)) {
// Load the areas map.
$map = \Drupal\openlayers\Openlayers::load('Map', 'farm_areas');
// Build the map and add it to the page content.
$page['content']['farm_areas'] = $map->build();
$page['content']['farm_areas'] = farm_map_build('farm_areas');
// Set the weight to -100 so that it appears on top.
$page['content']['farm_areas']['#weight'] = -100;

View file

@ -73,11 +73,8 @@ function farm_area_generate_page_build(&$page) {
// If this is the area generator form page, add the areas map.
if (current_path() == 'farm/areas/generate') {
// Load the areas map.
$map = \Drupal\openlayers\Openlayers::load('Map', 'farm_areas');
// Build the map and add it to the page content.
$page['content']['farm_areas'] = $map->build();
$page['content']['farm_areas'] = farm_map_build('farm_areas');
// Set the weight to 100 so that it appears on bottom.
$page['content']['farm_areas']['#weight'] = 100;

View file

@ -49,6 +49,40 @@ function farm_map_menu() {
return $items;
}
/**
* Build a map render array.
*
* @param string $map_name
* The machine name of the map.
*
* @return array
* Returns a Drupal render array.
*/
function farm_map_build($map_name) {
// Start with an empty build.
$build = array();
// If maps are disabled, bail.
if (!variable_get('farm_map_show', TRUE)) {
return $build;
}
// Load the map.
$map = \Drupal\openlayers\Openlayers::load('Map', $map_name);
// If the map didn't load, bail.
if (empty($map)) {
return $build;
}
// Build the map.
$build = $map->build();
// Return the build.
return $build;
}
/**
* Map settings form.
*/

View file

@ -47,11 +47,6 @@ function _farm_ui_views_post_render(&$view, &$output, &$cache) {
return;
}
// If dashboard maps are disabled in the farm_map module settings, bail.
if (!variable_get('farm_map_show', TRUE)) {
return;
}
// If there are any arguments, bail.
/**
* @todo
@ -62,11 +57,8 @@ function _farm_ui_views_post_render(&$view, &$output, &$cache) {
}
// Add the asset cluster map to the top of the View.
$map = \Drupal\openlayers\Openlayers::load('Map', 'farm_assets_' . $bundle);
if (!empty($map)) {
$map_build = $map->build();
$output = drupal_render($map_build) . $output;
}
$map_build = farm_map_build('farm_assets_' . $bundle);
$output = drupal_render($map_build) . $output;
}
/**