2014-11-12 20:27:59 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Code for the Farm Livestock feature.
|
|
|
|
*/
|
|
|
|
|
|
|
|
include_once 'farm_livestock.features.inc';
|
2014-12-01 20:22:38 +01:00
|
|
|
|
2015-06-20 18:00:17 +02:00
|
|
|
/**
|
|
|
|
* Implements hook_farm_area_type_info().
|
|
|
|
*/
|
|
|
|
function farm_livestock_farm_area_type_info() {
|
|
|
|
return array(
|
|
|
|
'paddock' => array(
|
|
|
|
'label' => t('Paddock'),
|
2015-09-08 19:29:23 +02:00
|
|
|
'style' => 'farm_map_style_green',
|
2015-07-31 03:01:08 +02:00
|
|
|
'weight' => 5,
|
2015-06-20 18:00:17 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-12-01 20:22:38 +01:00
|
|
|
/**
|
2015-03-13 01:07:56 +01:00
|
|
|
* Implements hook_farm_admin_actions().
|
2014-12-01 20:22:38 +01:00
|
|
|
*/
|
2015-03-13 01:07:56 +01:00
|
|
|
function farm_livestock_farm_admin_actions() {
|
2014-12-01 20:22:38 +01:00
|
|
|
|
2015-03-13 01:07:56 +01:00
|
|
|
// Define farm area actions.
|
2014-12-01 20:22:38 +01:00
|
|
|
$actions = array(
|
|
|
|
'animal' => array(
|
|
|
|
'title' => t('Add an animal'),
|
|
|
|
'href' => 'farm/asset/add/animal',
|
2015-03-14 15:58:18 +01:00
|
|
|
'views' => array(
|
|
|
|
'farm_animals',
|
2015-03-13 01:07:56 +01:00
|
|
|
),
|
2014-12-01 20:22:38 +01:00
|
|
|
),
|
2015-03-21 18:54:36 +01:00
|
|
|
'animal_group' => array(
|
|
|
|
'title' => t('Add a group'),
|
|
|
|
'href' => 'admin/structure/taxonomy/farm_animal_groups/add',
|
|
|
|
'views' => array(
|
|
|
|
'farm_animal_groups',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'animal_type' => array(
|
|
|
|
'title' => t('Add a type'),
|
|
|
|
'href' => 'admin/structure/taxonomy/farm_animal_types/add',
|
|
|
|
'views' => array(
|
|
|
|
'farm_animal_types',
|
|
|
|
),
|
|
|
|
),
|
2014-12-01 20:22:38 +01:00
|
|
|
);
|
2015-03-13 01:07:56 +01:00
|
|
|
return $actions;
|
2014-12-01 20:22:38 +01:00
|
|
|
}
|
|
|
|
|
2015-04-13 23:03:52 +02:00
|
|
|
/**
|
|
|
|
* Implements hook_farm_asset_breadcrumb().
|
|
|
|
*/
|
|
|
|
function farm_livestock_farm_asset_breadcrumb($farm_asset) {
|
|
|
|
|
|
|
|
// If the asset is an animal, add a link to the animals list.
|
|
|
|
$breadcrumb = array();
|
|
|
|
if ($farm_asset->type == 'animal') {
|
|
|
|
$breadcrumb[] = l(t('Animals'), 'farm/animals');
|
|
|
|
}
|
|
|
|
return $breadcrumb;
|
|
|
|
}
|
|
|
|
|
2015-03-19 22:29:51 +01:00
|
|
|
/**
|
|
|
|
* Implements hook_farm_asset_view_views().
|
|
|
|
*/
|
|
|
|
function farm_livestock_farm_asset_view_views($farm_asset) {
|
|
|
|
|
|
|
|
// If the entity is not an animal, bail.
|
|
|
|
if ($farm_asset->type != 'animal') {
|
2015-04-13 22:47:46 +02:00
|
|
|
return array();
|
2015-03-19 22:29:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return a list of Views to include on Animals.
|
|
|
|
return array(
|
|
|
|
'farm_log_activity',
|
|
|
|
'farm_log_observation',
|
|
|
|
'farm_log_movement',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-04-16 18:13:57 +02:00
|
|
|
/**
|
|
|
|
* Implements hook_farm_taxonomy_breadcrumb().
|
|
|
|
*/
|
|
|
|
function farm_livestock_farm_taxonomy_breadcrumb($term) {
|
|
|
|
$breadcrumb = array();
|
|
|
|
|
|
|
|
// Switch through available vocabularies.
|
|
|
|
switch ($term->vocabulary_machine_name) {
|
|
|
|
|
|
|
|
// If the term is in farm_animal_groups...
|
|
|
|
case 'farm_animal_groups':
|
|
|
|
$breadcrumb[] = l(t('Animals'), 'farm/animals');
|
|
|
|
$breadcrumb[] = l(t('Animal Groups'), 'farm/animals/groups');
|
|
|
|
break;
|
|
|
|
|
|
|
|
// If the term is in farm_animal_types...
|
|
|
|
case 'farm_animal_types':
|
|
|
|
$breadcrumb[] = l(t('Animals'), 'farm/animals');
|
|
|
|
$breadcrumb[] = l(t('Animal Types'), 'farm/animals/types');
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $breadcrumb;
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:11:44 +01:00
|
|
|
/**
|
|
|
|
* Implements hook_farm_taxonomy_term_view_views().
|
|
|
|
*/
|
|
|
|
function farm_livestock_farm_taxonomy_term_view_views($term) {
|
|
|
|
|
2015-03-21 18:40:38 +01:00
|
|
|
// Start a list of View names.
|
|
|
|
$views = array();
|
|
|
|
|
|
|
|
// Switch logic depending on the vocabulary.
|
|
|
|
switch ($term->vocabulary_machine_name) {
|
|
|
|
|
|
|
|
// Farm areas:
|
|
|
|
case 'farm_areas':
|
2015-04-10 17:12:30 +02:00
|
|
|
$views[] = array(
|
|
|
|
'name' => 'farm_animals',
|
|
|
|
'weight' => -10,
|
|
|
|
);
|
2015-03-21 18:40:38 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Farm animal groups:
|
|
|
|
case 'farm_animal_groups':
|
|
|
|
$views[] = array(
|
|
|
|
'name' => 'farm_animals',
|
|
|
|
'arg' => 2,
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Farm animal types:
|
|
|
|
case 'farm_animal_types':
|
|
|
|
$views[] = array(
|
|
|
|
'name' => 'farm_animals',
|
|
|
|
'arg' => 3,
|
|
|
|
);
|
|
|
|
break;
|
2015-03-21 16:11:44 +01:00
|
|
|
}
|
|
|
|
|
2015-03-21 18:40:38 +01:00
|
|
|
return $views;
|
2015-03-21 16:11:44 +01:00
|
|
|
}
|
|
|
|
|
2014-12-01 20:22:38 +01:00
|
|
|
/**
|
|
|
|
* Implements hook_farm_area_links().
|
|
|
|
*/
|
|
|
|
function farm_livestock_farm_area_links($id) {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
'title' => t('Animals'),
|
2015-03-21 16:11:44 +01:00
|
|
|
'href' => 'taxonomy/term/' . $id,
|
|
|
|
'options' => array(
|
|
|
|
'fragment' => 'Animals',
|
|
|
|
),
|
2014-12-01 20:22:38 +01:00
|
|
|
),
|
|
|
|
);
|
2015-04-13 22:47:46 +02:00
|
|
|
}
|