2014-03-31 16:10:39 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Code for the Farm Crop feature.
|
|
|
|
*/
|
|
|
|
|
|
|
|
include_once 'farm_crop.features.inc';
|
2014-11-19 19:27:27 +01:00
|
|
|
|
2014-11-26 22:55:20 +01:00
|
|
|
/**
|
2015-03-13 01:01:33 +01:00
|
|
|
* Implements hook_farm_admin_actions().
|
2014-11-26 22:55:20 +01:00
|
|
|
*/
|
2015-03-13 01:01:33 +01:00
|
|
|
function farm_crop_farm_admin_actions() {
|
2014-11-26 22:55:20 +01:00
|
|
|
|
|
|
|
// Define actions.
|
|
|
|
$actions = array(
|
|
|
|
'crop' => array(
|
|
|
|
'title' => t('Add a crop'),
|
|
|
|
'href' => 'admin/structure/taxonomy/farm_crops/add',
|
2015-03-13 01:01:33 +01:00
|
|
|
'paths' => array(
|
2015-04-10 19:27:00 +02:00
|
|
|
'farm/plantings',
|
|
|
|
'farm/plantings/crops',
|
2015-03-13 01:01:33 +01:00
|
|
|
),
|
2014-11-26 22:55:20 +01:00
|
|
|
),
|
2014-12-01 01:30:00 +01:00
|
|
|
'harvest' => array(
|
|
|
|
'title' => t('Add a harvest'),
|
|
|
|
'href' => 'log/add/farm_harvest',
|
2015-03-13 01:01:33 +01:00
|
|
|
'assets' => array(
|
2015-04-13 22:46:16 +02:00
|
|
|
'planting',
|
2015-03-13 01:01:33 +01:00
|
|
|
),
|
2015-03-14 15:55:32 +01:00
|
|
|
'views' => array(
|
|
|
|
'farm_log_harvest',
|
|
|
|
),
|
2014-12-01 01:30:00 +01:00
|
|
|
),
|
2014-12-01 01:30:19 +01:00
|
|
|
'input' => array(
|
|
|
|
'title' => t('Add an input'),
|
|
|
|
'href' => 'log/add/farm_input',
|
2015-03-13 01:01:33 +01:00
|
|
|
'assets' => array(
|
2015-04-13 22:46:16 +02:00
|
|
|
'planting',
|
2015-03-13 01:01:33 +01:00
|
|
|
),
|
2015-03-14 15:55:32 +01:00
|
|
|
'views' => array(
|
|
|
|
'farm_log_input',
|
|
|
|
),
|
|
|
|
'paths' => array(
|
|
|
|
'taxonomy/term/%',
|
|
|
|
),
|
2014-12-01 01:30:19 +01:00
|
|
|
),
|
2014-11-26 22:55:20 +01:00
|
|
|
'planting' => array(
|
|
|
|
'title' => t('Add a planting'),
|
|
|
|
'href' => 'farm/asset/add/planting',
|
2015-03-14 15:55:32 +01:00
|
|
|
'views' => array(
|
|
|
|
'farm_plantings',
|
|
|
|
),
|
2014-11-26 22:55:20 +01:00
|
|
|
),
|
|
|
|
'seeding' => array(
|
2014-12-01 01:30:00 +01:00
|
|
|
'title' => t('Add a seeding'),
|
2014-11-26 22:55:20 +01:00
|
|
|
'href' => 'log/add/farm_seeding',
|
2015-03-13 01:01:33 +01:00
|
|
|
'assets' => array(
|
2015-04-13 22:46:16 +02:00
|
|
|
'planting',
|
2015-03-13 01:01:33 +01:00
|
|
|
),
|
2015-03-14 15:55:32 +01:00
|
|
|
'views' => array(
|
|
|
|
'farm_log_seeding',
|
|
|
|
),
|
2014-11-26 22:55:20 +01:00
|
|
|
),
|
|
|
|
'transplanting' => array(
|
2014-12-01 01:30:00 +01:00
|
|
|
'title' => t('Add a transplanting'),
|
2014-11-26 22:55:20 +01:00
|
|
|
'href' => 'log/add/farm_transplanting',
|
2015-03-13 01:01:33 +01:00
|
|
|
'assets' => array(
|
2015-04-13 22:46:16 +02:00
|
|
|
'planting',
|
2015-03-13 01:01:33 +01:00
|
|
|
),
|
2015-03-14 15:55:32 +01:00
|
|
|
'views' => array(
|
|
|
|
'farm_log_transplanting',
|
|
|
|
),
|
2014-11-26 22:55:20 +01:00
|
|
|
),
|
|
|
|
);
|
2015-03-13 01:01:33 +01:00
|
|
|
return $actions;
|
2014-11-26 22:55:20 +01:00
|
|
|
}
|
|
|
|
|
2015-04-13 23:02:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2015-04-16 18:13:21 +02:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2015-03-19 22:30:08 +01:00
|
|
|
/**
|
|
|
|
* 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();
|
2015-03-19 22:30:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-03-21 15:49:09 +01:00
|
|
|
/**
|
|
|
|
* 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,
|
2015-04-10 17:11:49 +02:00
|
|
|
'weight' => -20,
|
2015-03-21 15:49:09 +01:00
|
|
|
);
|
|
|
|
$views[] = array(
|
|
|
|
'name' => 'farm_log_input',
|
|
|
|
'arg' => 2,
|
|
|
|
);
|
|
|
|
break;
|
2015-03-21 15:55:43 +01:00
|
|
|
|
2015-04-13 22:46:16 +02:00
|
|
|
// Farm crops.
|
2015-03-21 15:55:43 +01:00
|
|
|
case 'farm_crops':
|
|
|
|
$views[] = array(
|
|
|
|
'name' => 'farm_plantings',
|
|
|
|
'arg' => 2,
|
|
|
|
);
|
|
|
|
break;
|
2015-03-21 18:34:03 +01:00
|
|
|
|
2015-04-13 22:46:16 +02:00
|
|
|
// Farm crop family.
|
2015-03-21 18:34:03 +01:00
|
|
|
case 'farm_crop_families':
|
|
|
|
$views[] = 'farm_crops';
|
|
|
|
break;
|
2015-03-21 15:49:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $views;
|
|
|
|
}
|
|
|
|
|
2014-11-19 19:27:27 +01:00
|
|
|
/**
|
|
|
|
* 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');
|
2014-11-19 19:27:27 +01:00
|
|
|
}
|
2014-12-01 02:09:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_farm_area_links().
|
|
|
|
*/
|
|
|
|
function farm_crop_farm_area_links($id) {
|
|
|
|
return array(
|
2014-12-01 15:03:54 +01:00
|
|
|
array(
|
|
|
|
'title' => t('Inputs'),
|
2015-03-21 15:49:09 +01:00
|
|
|
'href' => 'taxonomy/term/' . $id,
|
|
|
|
'options' => array(
|
|
|
|
'fragment' => 'Inputs',
|
|
|
|
),
|
2014-12-01 15:03:54 +01:00
|
|
|
'weight' => 10,
|
|
|
|
),
|
2014-12-01 20:19:06 +01:00
|
|
|
array(
|
|
|
|
'title' => t('Plantings'),
|
2015-03-21 15:49:09 +01:00
|
|
|
'href' => 'taxonomy/term/' . $id,
|
|
|
|
'options' => array(
|
|
|
|
'fragment' => 'Plantings',
|
|
|
|
),
|
2014-12-01 20:19:06 +01:00
|
|
|
),
|
2014-12-01 02:09:58 +01:00
|
|
|
);
|
|
|
|
}
|