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

216 lines
4.6 KiB
Text
Raw Normal View History

<?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/plantings',
'farm/plantings/crops',
),
),
'harvest' => array(
'title' => t('Add a harvest'),
'href' => 'log/add/farm_harvest',
'assets' => array(
2015-04-13 22:46:16 +02:00
'planting',
),
'views' => array(
'farm_log_harvest',
),
),
2014-12-01 01:30:19 +01:00
'input' => array(
'title' => t('Add an input'),
'href' => 'log/add/farm_input',
'assets' => array(
2015-04-13 22:46:16 +02:00
'planting',
),
'views' => array(
'farm_log_input',
),
'paths' => array(
'taxonomy/term/%',
),
2014-12-01 01:30:19 +01:00
),
'planting' => array(
'title' => t('Add a planting'),
'href' => 'farm/asset/add/planting',
'views' => array(
'farm_plantings',
),
),
'seeding' => array(
'title' => t('Add a seeding'),
'href' => 'log/add/farm_seeding',
'assets' => array(
2015-04-13 22:46:16 +02:00
'planting',
),
'views' => array(
'farm_log_seeding',
),
),
'transplanting' => array(
'title' => t('Add a transplanting'),
'href' => 'log/add/farm_transplanting',
'assets' => array(
2015-04-13 22:46:16 +02:00
'planting',
),
'views' => array(
'farm_log_transplanting',
),
),
);
return $actions;
}
/**
* Implements hook_farm_asset_breadcrumb().
*/
function farm_crop_farm_asset_breadcrumb($farm_asset) {
// If the asset is a planting, add a link to the animals list.
$breadcrumb = array();
if ($farm_asset->type == 'planting') {
$breadcrumb[] = l(t('Plantings'), 'farm/plantings');
}
return $breadcrumb;
}
/**
* Implements hook_farm_taxonomy_breadcrumb().
*/
function farm_crop_farm_taxonomy_breadcrumb($term) {
$breadcrumb = array();
// Switch through available vocabularies.
switch ($term->vocabulary_machine_name) {
// If the term is in farm_crops...
case 'farm_crops':
$breadcrumb[] = l(t('Plantings'), 'farm/plantings');
$breadcrumb[] = l(t('Crops'), 'farm/plantings/crops');
break;
// If the term is in farm_crop_families...
case 'farm_crop_families':
$breadcrumb[] = l(t('Plantings'), 'farm/plantings');
$breadcrumb[] = t('Crop Families');
break;
}
return $breadcrumb;
}
/**
* 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') {
2015-04-13 22:46:16 +02:00
return array();
}
// 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_farm_taxonomy_term_view_views().
*/
function farm_crop_farm_taxonomy_term_view_views($term) {
// Start a list of View names.
$views = array();
// Switch logic depending on the vocabulary.
switch ($term->vocabulary_machine_name) {
// Farm areas:
case 'farm_areas':
$views[] = array(
'name' => 'farm_plantings',
'arg' => 1,
'weight' => -20,
);
$views[] = array(
'name' => 'farm_log_input',
'arg' => 2,
);
break;
2015-04-13 22:46:16 +02:00
// Farm crops.
case 'farm_crops':
$views[] = array(
'name' => 'farm_plantings',
'arg' => 2,
);
break;
2015-04-13 22:46:16 +02:00
// Farm crop family.
case 'farm_crop_families':
$views[] = 'farm_crops';
break;
}
return $views;
}
/**
* 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.
2014-12-01 03:51:25 +01:00
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' => 'taxonomy/term/' . $id,
'options' => array(
'fragment' => 'Inputs',
),
'weight' => 10,
),
2014-12-01 20:19:06 +01:00
array(
'title' => t('Plantings'),
'href' => 'taxonomy/term/' . $id,
'options' => array(
'fragment' => 'Plantings',
),
2014-12-01 20:19:06 +01:00
),
);
}