diff --git a/modules/farm/farm_area/farm_area.module b/modules/farm/farm_area/farm_area.module index 4f6a6c8f..81851fbf 100644 --- a/modules/farm/farm_area/farm_area.module +++ b/modules/farm/farm_area/farm_area.module @@ -265,6 +265,45 @@ function farm_area_page_build(&$page) { } } +/** + * Implements hook_entity_view_alter(). + */ +function farm_area_entity_view_alter(&$build, $type) { + + // If it's not a taxonomy_term, or if the entity object is not available, + // bail. + if ($type != 'taxonomy_term' || empty($build['#term'])) { + return; + } + + // Alias the area variable. + $area = $build['#term']; + + // If it isn't a farm_areas term, bail. + if ($area->vocabulary_machine_name != 'farm_areas') { + return; + } + + // Get the area's calculated area. + $calculated_area = farm_area_calculate_area($area->tid); + + // If the calculated area isn't available, bail. + if (empty($calculated_area)) { + return; + } + + // Build the calculated area display. + $output = '' . t('Calculated area') . ': ' . $calculated_area; + + // Add it to the build array. + $build['calculated_area'] = array( + '#markup' => $output, + '#prefix' => '
', + '#suffix' => '
', + '#weight' => 1, + ); +} + /** * Helper function to extract geometries from areas. *