154 lines
3.8 KiB
Plaintext
154 lines
3.8 KiB
Plaintext
<?php
|
|
/**
|
|
* @file
|
|
* Code for the Farm Area feature.
|
|
*/
|
|
|
|
include_once 'farm_area.features.inc';
|
|
|
|
/**
|
|
* Implements hook_farm_admin_actions().
|
|
*/
|
|
function farm_area_farm_admin_actions() {
|
|
|
|
// Define farm admin actions.
|
|
$actions = array(
|
|
'area' => array(
|
|
'title' => t('Add an area'),
|
|
'href' => 'admin/structure/taxonomy/farm_areas/add',
|
|
'views' => array(
|
|
'farm_areas',
|
|
),
|
|
'paths' => array(
|
|
'farm',
|
|
),
|
|
),
|
|
);
|
|
return $actions;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_farm_taxonomy_breadcrumb().
|
|
*/
|
|
function farm_area_farm_taxonomy_breadcrumb($term) {
|
|
$breadcrumb = array();
|
|
|
|
// If the term is in farm_areas, add a link to /farm/areas.
|
|
if ($term->vocabulary_machine_name == 'farm_areas') {
|
|
$breadcrumb[] = l(t('Areas'), 'farm/areas');
|
|
}
|
|
|
|
return $breadcrumb;
|
|
}
|
|
|
|
/**
|
|
* Generate area links, sorted by weight.
|
|
*
|
|
* @param int $id
|
|
* The area id.
|
|
* @param string $separator
|
|
* Characters to use as a separator between links in the returned string.
|
|
*
|
|
* @return string
|
|
* Returns a string of links.
|
|
*/
|
|
function farm_area_get_links($id, $separator = ' | ') {
|
|
|
|
// Call out to modules that want to provide links.
|
|
$area_links = module_invoke_all('farm_area_links', check_plain($id));
|
|
|
|
// Build an index of links and their weights.
|
|
$weight_index = array();
|
|
foreach ($area_links as $key => $link) {
|
|
|
|
// Default the weight to zero if it hasn't been set.
|
|
if (!isset($link['weight'])) {
|
|
$link['weight'] = 0;
|
|
}
|
|
|
|
// Assign the weight to the index, based on it's key in the original array.
|
|
$weight_index[$key] = $link['weight'];
|
|
}
|
|
|
|
// Sort the index by weight.
|
|
asort($weight_index);
|
|
|
|
// Rebuild the array of links based on their weights.
|
|
$sorted_area_links = array();
|
|
foreach ($weight_index as $key => $weight) {
|
|
$sorted_area_links[] = $area_links[$key];
|
|
}
|
|
|
|
// Generate an array of Drupal links.
|
|
$links = array();
|
|
foreach ($sorted_area_links as $link) {
|
|
|
|
// If a title and href are available...
|
|
if (!empty($link['title']) && !empty($link['href'])) {
|
|
|
|
// Build link options.
|
|
$options = array();
|
|
if (!empty($link['options'])) {
|
|
$options = $link['options'];
|
|
}
|
|
|
|
// Build the link and add it to the array.
|
|
$links[] = l($link['title'], $link['href'], $options);
|
|
}
|
|
}
|
|
|
|
// Convert to a string with a separator and return.
|
|
return implode($separator, $links);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_openlayers_map_preprocess_alter().
|
|
*/
|
|
function farm_area_openlayers_map_preprocess_alter(&$map = array()) {
|
|
|
|
// Define the layer we are going to add.
|
|
$layer = 'farm_area_data_all';
|
|
|
|
// Add the 'All Areas' layer to Farm Geofield Map.
|
|
if (!empty($map['map_name']) && $map['map_name'] == 'farm_map_geofield') {
|
|
|
|
// Add the farm_soil_nrcs layer.
|
|
$map['layers'] += array($layer => $layer);
|
|
|
|
// Activate the layer by default.
|
|
$map['layer_activated'] += array($layer => $layer);
|
|
|
|
// Show the layer in the switcher.
|
|
$map['layer_switcher'] += array($layer => $layer);
|
|
|
|
// Set the layer style to Farm Grey.
|
|
$map['layer_styles'] += array($layer => 'farm_grey');
|
|
|
|
// Set the layer weight so that it is on the bottom.
|
|
$map['layer_weight'] += array($layer => 100);
|
|
|
|
// Zoom to the "All areas" layer.
|
|
if (!empty($map['behaviors']['openlayers_behavior_zoomtolayer'])) {
|
|
$map['behaviors']['openlayers_behavior_zoomtolayer']['zoomtolayer'][$layer] = $layer;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implements hook_panels_pre_render().
|
|
*/
|
|
function farm_area_panels_pre_render($panels_display, $renderer) {
|
|
|
|
// If this is the Farm Plan panel page, display the areas map.
|
|
$output = '';
|
|
/*
|
|
* @todo
|
|
* Find a better way to identify this panel page. If the title ever
|
|
* changes, this will stop working.
|
|
*/
|
|
if ($panels_display->title == 'Farm Plan') {
|
|
$output .= views_embed_view('farm_areas', 'block');
|
|
}
|
|
return $output;
|
|
}
|