You are here

function theme_farm_map in farmOS 7

Returns HTML that wraps the farm map..

1 theme call to theme_farm_map()
farm_map_element_info in modules/farm/farm_map/farm_map.module
Implements hook_element_info().

File

modules/farm/farm_map/farm_map.module, line 106

Code

function theme_farm_map(&$vars) {

  // Get the element.
  $element = $vars['element'];

  // Load the farmOS-map.js library.
  libraries_load('farmOS-map');

  // Get the map name (default to 'farm_map').
  if (empty($element['#map_name'])) {
    $element['#map_name'] = 'farm_map';
  }
  $map_name = $element['#map_name'];

  // Generate a map div ID, if one wasn't provided.
  $id = drupal_html_id($map_name);
  if (!empty($element['#attributes']['id'])) {
    $id = $element['#attributes']['id'];
  }
  else {
    $element['#attributes']['id'] = $id;
  }

  // Add 'farm-map' CSS class.
  if (empty($element['#attributes']['class']) || !in_array('farm-map', $element['#attributes']['class'])) {
    $element['#attributes']['class'][] = 'farm-map';
  }

  // Create a settings array to be passed to JavaScript.
  $settings = array(
    'farm_map' => array(),
  );

  // Add a setting that defines the base path of the site.
  // We do this instead of using Drupal.settings.basePath in Javascript
  // because that variable does not take into account whether or not clean
  // URLs are enabled.
  $settings['farm_map']['base_path'] = str_replace('farm', '', url('farm'));

  // Load the system of measurement, and save it to settings.
  $system_of_measurement = farm_quantity_system_of_measurement();
  $settings['farm_map']['units'] = $system_of_measurement;

  // If WKT is set, add it to the settings associated with the element ID.
  if (isset($element['#wkt'])) {
    $settings['farm_map']['wkt'][$id] = $element['#wkt'];
  }

  // Add the JavaScript settings.
  drupal_add_js($settings, 'setting');

  // Add farm_map.js, which will run farmOS.map.create().
  drupal_add_js(drupal_get_path('module', 'farm_map') . '/js/farm_map.js');

  // Add farm_map.css.
  drupal_add_css(drupal_get_path('module', 'farm_map') . '/css/farm_map.css');

  // Allow other modules to perform logic.
  module_invoke_all('farm_map_view', $map_name, $element);

  // Return a simple div with attributes.
  return '<div' . drupal_attributes($element['#attributes']) . '></div>';
}