mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
Provide local action links for crops, plantings, seedings, and transplantings.
This commit is contained in:
parent
ffde31c651
commit
b67e00af59
1 changed files with 81 additions and 0 deletions
|
@ -6,6 +6,87 @@
|
|||
|
||||
include_once 'farm_crop.features.inc';
|
||||
|
||||
/**
|
||||
* Implements hook_menu_local_tasks_alter().
|
||||
*/
|
||||
function farm_crop_menu_local_tasks_alter(&$data, $router_item, $root_path) {
|
||||
|
||||
// Define actions.
|
||||
$actions = array(
|
||||
'crop' => array(
|
||||
'title' => t('Add a crop'),
|
||||
'href' => 'admin/structure/taxonomy/farm_crops/add',
|
||||
),
|
||||
'planting' => array(
|
||||
'title' => t('Add a planting'),
|
||||
'href' => 'farm/asset/add/planting',
|
||||
),
|
||||
'seeding' => array(
|
||||
'title' => t('Record a seeding'),
|
||||
'href' => 'log/add/farm_seeding',
|
||||
),
|
||||
'transplanting' => array(
|
||||
'title' => t('Record a transplanting'),
|
||||
'href' => 'log/add/farm_transplanting',
|
||||
),
|
||||
);
|
||||
|
||||
// Define actions for various paths.
|
||||
$path_actions = array(
|
||||
'admin/farm/crops' => array('crop'),
|
||||
'admin/farm/crops/plantings' => array('planting'),
|
||||
'admin/farm/plan/seedings' => array('seeding'),
|
||||
'admin/farm/plan/transplantings' => array('transplanting'),
|
||||
'farm/asset/%' => array('seeding', 'transplanting'),
|
||||
'taxonomy/term/%/seedings' => array('seeding'),
|
||||
'taxonomy/term/%/transplantings' => array('transplanting'),
|
||||
);
|
||||
|
||||
// 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 movements path...
|
||||
if (in_array($root_path, array('farm/asset/%', 'farm/asset/%/seedings', 'farm/asset/%/transplantings'))) {
|
||||
|
||||
// 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 != 'planting') {
|
||||
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
|
||||
// prepopualte asset reference fields in log entities.
|
||||
// See hook_form_alter() below
|
||||
$output['#link']['localized_options']['query']['farm_asset'] = $asset_id;
|
||||
}
|
||||
|
||||
// Add the action output.
|
||||
$data['actions']['output'][] = $output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue