mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
113 lines
No EOL
3.4 KiB
Text
113 lines
No EOL
3.4 KiB
Text
<?php
|
|
/**
|
|
* @file
|
|
* Code for the Farm Crop feature.
|
|
*/
|
|
|
|
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',
|
|
),
|
|
'harvest' => array(
|
|
'title' => t('Add a harvest'),
|
|
'href' => 'log/add/farm_harvest',
|
|
),
|
|
'input' => array(
|
|
'title' => t('Add an input'),
|
|
'href' => 'log/add/farm_input',
|
|
),
|
|
'planting' => array(
|
|
'title' => t('Add a planting'),
|
|
'href' => 'farm/asset/add/planting',
|
|
),
|
|
'seeding' => array(
|
|
'title' => t('Add a seeding'),
|
|
'href' => 'log/add/farm_seeding',
|
|
),
|
|
'transplanting' => array(
|
|
'title' => t('Add 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/harvests' => array('harvest'),
|
|
'admin/farm/plan/inputs' => array('input'),
|
|
'admin/farm/plan/seedings' => array('seeding'),
|
|
'admin/farm/plan/transplantings' => array('transplanting'),
|
|
'farm/asset/%' => array('seeding', 'transplanting', 'harvest', 'input'),
|
|
'taxonomy/term/%/harvests' => array('harvest'),
|
|
'taxonomy/term/%/inputs' => array('input'),
|
|
'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 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 != '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().
|
|
*/
|
|
function farm_crop_form_alter(&$form, &$form_state, $form_id) {
|
|
|
|
// If this is a log form with a planting reference field...
|
|
if ($form_id == 'log_form' && !empty($form['field_farm_planting'])) {
|
|
|
|
// Alter the form with the farm_log helper function.
|
|
farm_log_form_prepopulate_asset($form, $field_name = 'field_farm_planting');
|
|
}
|
|
} |