farmOS/farm_livestock.module

151 lines
3.2 KiB
Plaintext

<?php
/**
* @file
* Code for the Farm Livestock feature.
*/
include_once 'farm_livestock.features.inc';
/**
* Implements hook_farm_admin_actions().
*/
function farm_livestock_farm_admin_actions() {
// Define farm area actions.
$actions = array(
'animal' => array(
'title' => t('Add an animal'),
'href' => 'farm/asset/add/animal',
'views' => array(
'farm_animals',
),
),
'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',
),
),
);
return $actions;
}
/**
* 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;
}
/**
* 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') {
return array();
}
// Return a list of Views to include on Animals.
return array(
'farm_log_activity',
'farm_log_observation',
'farm_log_movement',
);
}
/**
* 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;
}
/**
* Implements hook_farm_taxonomy_term_view_views().
*/
function farm_livestock_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_animals',
'weight' => -10,
);
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;
}
return $views;
}
/**
* Implements hook_farm_area_links().
*/
function farm_livestock_farm_area_links($id) {
return array(
array(
'title' => t('Animals'),
'href' => 'taxonomy/term/' . $id,
'options' => array(
'fragment' => 'Animals',
),
),
);
}