mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
Implement hook_farm_admin_action() to provide action links.
This commit is contained in:
parent
6c7ba578de
commit
21ad477ffa
2 changed files with 16 additions and 106 deletions
|
@ -7,91 +7,23 @@
|
|||
include_once 'farm_livestock.features.inc';
|
||||
|
||||
/**
|
||||
* Implements hook_menu_local_tasks_alter().
|
||||
* Implements hook_farm_admin_actions().
|
||||
*/
|
||||
function farm_livestock_menu_local_tasks_alter(&$data, $router_item, $root_path) {
|
||||
function farm_livestock_farm_admin_actions() {
|
||||
|
||||
// Define actions.
|
||||
// Define farm area actions.
|
||||
$actions = array(
|
||||
'animal' => array(
|
||||
'title' => t('Add an animal'),
|
||||
'href' => 'farm/asset/add/animal',
|
||||
'paths' => array(
|
||||
'farm/area/%/animals',
|
||||
'farm/livestock',
|
||||
'farm/livestock/animals',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Define actions for various paths.
|
||||
$path_actions = array(
|
||||
'farm/area/%/animals' => array('animal'),
|
||||
'farm/livestock' => array('animal'),
|
||||
'farm/livestock/animals' => array('animal'),
|
||||
);
|
||||
|
||||
// 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 != 'animal') {
|
||||
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;
|
||||
}
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,41 +7,19 @@
|
|||
include_once 'farm_livestock_eggs.features.inc';
|
||||
|
||||
/**
|
||||
* Implements hook_menu_local_tasks_alter().
|
||||
* Implements hook_farm_admin_actions().
|
||||
*/
|
||||
function farm_livestock_eggs_menu_local_tasks_alter(&$data, $router_item, $root_path) {
|
||||
function farm_livestock_eggs_farm_admin_actions() {
|
||||
|
||||
// Define actions.
|
||||
// Define farm area actions.
|
||||
$actions = array(
|
||||
'eggs' => array(
|
||||
'title' => t('Add eggs'),
|
||||
'href' => 'log/add/farm_eggs',
|
||||
'paths' => array(
|
||||
'farm/livestock/eggs',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Define actions for various paths.
|
||||
$path_actions = array(
|
||||
'farm/livestock/eggs' => array('eggs'),
|
||||
);
|
||||
|
||||
// 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,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Add the action output.
|
||||
$data['actions']['output'][] = $output;
|
||||
}
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue