farmOS/modules/farm/farm_equipment/farm_equipment.module

176 lines
3.7 KiB
Plaintext

<?php
/**
* @file
* Code for the Farm Equipment feature.
*/
include_once 'farm_equipment.features.inc';
/**
* Implements hook_farm_ui_entities().
*/
function farm_equipment_farm_ui_entities() {
return array(
'farm_asset' => array(
'equipment' => array(
'label' => t('Equipment'),
'label_plural' => t('Equipment'),
'view' => 'farm_equipment',
),
),
'log' => array(
'farm_maintenance' => array(
'label' => t('Maintenance'),
'label_plural' => t('Maintenance'),
'view' => 'farm_log_maintenance',
),
),
);
}
/**
* Implements hook_farm_ui_actions().
*/
function farm_equipment_farm_ui_actions() {
// Define farm equipment actions.
$actions = array(
'maintenance' => array(
'title' => t('Add maintenance'),
'href' => 'log/add/farm_maintenance',
'assets' => array(
'equipment',
),
),
);
return $actions;
}
/**
* Implements hook_farm_asset_view_views().
*/
function farm_equipment_farm_asset_view_views($farm_asset) {
// If the entity is not equipment, bail.
if ($farm_asset->type != 'equipment') {
return array();
}
// Return a list of Views to include on Equipment.
return array(
array(
'name' => 'farm_log_activity',
'weight' => 0,
),
array(
'name' => 'farm_log_observation',
'weight' => 10,
),
array(
'name' => 'farm_log_maintenance',
'weight' => 20,
),
array(
'name' => 'farm_log_input',
'weight' => 50,
),
array(
'name' => 'farm_log_movement',
'weight' => 100,
),
);
}
/**
* Implements hook_farm_taxonomy_term_view_views().
*/
function farm_equipment_farm_taxonomy_term_view_views($term) {
// If the term is not an area, bail.
if ($term->vocabulary_machine_name != 'farm_areas') {
return array();
}
// Return a list of Views to include on Areas.
return array(
array(
'name' => 'farm_equipment',
'weight' => -10,
),
);
}
/**
* Implements hook_farm_area_links().
*/
function farm_equipment_farm_area_links($id) {
$links = array();
// Add link to equipment.
$view = views_get_view('farm_equipment');
$view->preview('default', array($id));
if ($view->total_rows > 0) {
$links[] = array(
'title' => t('Equipment') . ': ' . $view->total_rows,
'href' => 'farm/assets/equipment/' . $id,
);
}
return $links;
}
/**
* Implements hook_views_post_render().
*/
function farm_equipment_views_post_render(&$view, &$output, &$cache) {
// If this is the Farm Equipment page...
if ($view->name == 'farm_equipment' && $view->current_display == 'page') {
// If dashboard maps are disabled in the farm_map module settings, bail.
if (!variable_get('farm_map_show', TRUE)) {
return;
}
// If there are any arguments, bail.
/**
* @todo
* Display a map that is filtered by the same arguments.
*/
if (!empty($view->args)) {
return;
}
// If the View result is not empty...
if (!empty($view->result)) {
// Add the Equipment asset map to the top of the View.
$map = \Drupal\openlayers\Openlayers::load('Map', 'farm_assets_equipment');
if (!empty($map)) {
$map_build = $map->build();
$output = drupal_render($map_build) . $output;
}
}
}
}
/**
* Implements hook_farm_log_allowed_asset_reference_type().
*/
function farm_equipment_farm_log_allowed_asset_reference_type($log_type) {
// On maintenance logs, only equipment can be referenced.
if ($log_type == 'farm_maintenance') {
return 'equipment';
}
}
/**
* Implements hook_farm_log_categories().
*/
function farm_equipment_farm_log_categories() {
// Provide an "Equipment" log category.
return array('Equipment');
}