Provide a Views field handler for area details.

This commit is contained in:
Michael Stenta 2015-05-15 10:55:39 -04:00
parent e680e6c0bf
commit 82529d5041
3 changed files with 63 additions and 0 deletions

View File

@ -38,4 +38,5 @@ features[taxonomy][] = farm_areas
features[variable][] = pathauto_taxonomy_term_farm_areas_pattern
features[views_view][] = farm_area_data
features[views_view][] = farm_areas
files[] = views/handlers/farm_area_handler_field_details.inc
files[] = views/handlers/farm_area_handler_field_links.inc

View File

@ -10,6 +10,15 @@
*/
function farm_area_views_data_alter(&$data) {
// Add a field for farm area details.
$data['taxonomy_term_data']['farm_area_details'] = array(
'field' => array(
'title' => t('Area Details'),
'help' => t('Details that are relevant to farm areas.'),
'handler' => 'farm_area_handler_field_details',
),
);
// Add a field for farm area links.
$data['taxonomy_term_data']['farm_area_links'] = array(
'field' => array(

View File

@ -0,0 +1,53 @@
<?php
/**
* @file
* Field handler to present farm area links.
*/
/**
* Field handler to present farm area details.
*/
class farm_area_handler_field_details extends views_handler_field {
/**
* {@inheritdoc}
*/
public function construct() {
// Inherit the parent's construction.
parent::construct();
// Add the term id as an additional field to load to ensure that it is
// available in this handler.
$this->additional_fields['tid'] = 'tid';
}
/**
* {@inheritdoc}
*/
public function query() {
// Ensure the main table for this field is included.
$this->ensure_my_table();
// Include additional fields (like term id defined in $this->construct())
$this->add_additional_fields();
}
/**
* {@inheritdoc}
*/
public function render($values) {
// Load the term id value.
$aid = $this->get_value($values, 'tid');
// Generate the area details.
$area_details = farm_area_get_details($aid);
// Return the details.
return $area_details;
}
}