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

130 lines
2.7 KiB
Text

<?php
/**
* @file
* Code for the Farm Crop feature.
*/
include_once 'farm_crop.features.inc';
/**
* Implements hook_farm_admin_actions().
*/
function farm_crop_farm_admin_actions() {
// Define actions.
$actions = array(
'crop' => array(
'title' => t('Add a crop'),
'href' => 'admin/structure/taxonomy/farm_crops/add',
'paths' => array(
'farm/crops',
),
),
'harvest' => array(
'title' => t('Add a harvest'),
'href' => 'log/add/farm_harvest',
'assets' => array(
'planting'
),
'views' => array(
'farm_log_harvest',
),
),
'input' => array(
'title' => t('Add an input'),
'href' => 'log/add/farm_input',
'assets' => array(
'planting'
),
'views' => array(
'farm_log_input',
),
'paths' => array(
'taxonomy/term/%',
),
),
'planting' => array(
'title' => t('Add a planting'),
'href' => 'farm/asset/add/planting',
'views' => array(
'farm_plantings',
),
'paths' => array(
'farm/crops',
),
),
'seeding' => array(
'title' => t('Add a seeding'),
'href' => 'log/add/farm_seeding',
'assets' => array(
'planting'
),
'views' => array(
'farm_log_seeding',
),
),
'transplanting' => array(
'title' => t('Add a transplanting'),
'href' => 'log/add/farm_transplanting',
'assets' => array(
'planting'
),
'views' => array(
'farm_log_transplanting',
),
),
);
return $actions;
}
/**
* Implements hook_farm_asset_view_views().
*/
function farm_crop_farm_asset_view_views($farm_asset) {
// If the entity is not a planting, bail.
if ($farm_asset->type != 'planting') {
return;
}
// Return a list of Views to include on Plantings.
return array(
'farm_log_seeding',
'farm_log_transplanting',
'farm_log_input',
'farm_log_harvest',
'farm_log_activity',
'farm_log_observation',
'farm_log_movement',
);
}
/**
* 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_farm_planting');
}
}
/**
* Implements hook_farm_area_links().
*/
function farm_crop_farm_area_links($id) {
return array(
array(
'title' => t('Inputs'),
'href' => 'farm/area/' . $id . '/inputs',
'weight' => 10,
),
array(
'title' => t('Plantings'),
'href' => 'farm/area/' . $id . '/plantings',
),
);
}