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

Implement hook_menu_local_tasks_alter() to provide equipment action links, and hook_farm_area_links() to provide farm area links.

This commit is contained in:
Michael Stenta 2014-12-08 11:23:24 -05:00
parent b3bbfddeb4
commit 11be4c8269

View file

@ -5,3 +5,103 @@
*/
include_once 'farm_equipment.features.inc';
/**
* Implements hook_menu_local_tasks_alter().
*/
function farm_equipment_menu_local_tasks_alter(&$data, $router_item, $root_path) {
// Define actions.
$actions = array(
'animal' => array(
'title' => t('Add equipment'),
'href' => 'farm/asset/add/equipment',
),
);
// Define actions for various paths.
$path_actions = array(
'farm/area/%/equipment' => array('equipment'),
'admin/farm/equipment' => array('equipment'),
'admin/farm/equipment/list' => array('equipment'),
);
// Add actions depending on the root path.
if (array_key_exists($root_path, $path_actions)) {
foreach ($path_actions[$root_path] as $action) {
$output = array(
'#theme' => 'menu_local_action',
'#link' => array(
'title' => $actions[$action]['title'],
'href' => $actions[$action]['href'],
'localized_options' => array(
'query' => array(
'destination' => $root_path,
),
),
),
);
// If this is a farm asset path...
if (substr($root_path, 0, 12) == 'farm/asset/%') {
// Get the asset id from the path.
$asset_id = check_plain(arg(2));
// Load the asset.
$farm_asset = farm_asset_load($asset_id);
// If the farm asset is not a planting, bail.
if (empty($farm_asset->type) || $farm_asset->type != 'equipment') {
continue;
}
// Set the destination to the farm asset page.
$output['#link']['localized_options']['query']['destination'] = 'farm/asset/' . $asset_id;
// Set the farm_asset query string to the asset id. This will be used to
// prepopulate asset reference fields in log entities.
// See hook_form_alter() below
$output['#link']['localized_options']['query']['farm_asset'] = $asset_id;
}
// Or, if this is a farm area path...
elseif ($root_path == 'taxonomy/term/%' || substr($root_path, 0, 11) == 'farm/area/%') {
// Get the area id from the path.
$area_id = check_plain(arg(2));
// Load the area.
$farm_area = taxonomy_term_load($area_id);
// If the taxonomy term is not a farm_area, bail.
if (empty($farm_area->vocabulary_machine_name) || $farm_area->vocabulary_machine_name != 'farm_areas') {
continue;
}
// Set the destination to the farm asset page.
$output['#link']['localized_options']['query']['destination'] = 'taxonomy/term/' . $area_id;
// Set the farm_area query string to the area id. This will be used to
// prepopulate area(s) reference fields in log entities.
// See hook_form_alter() below
$output['#link']['localized_options']['query']['farm_area'] = $area_id;
}
// Add the action output.
$data['actions']['output'][] = $output;
}
}
}
/**
* Implements hook_farm_area_links().
*/
function farm_equipment_farm_area_links($id) {
return array(
array(
'title' => t('Equipment'),
'href' => 'farm/area/' . $id . '/equipment',
),
);
}