You are here

function farm_movement_asset_location_markup in farmOS 7

Generate markup that describes an asset's current location.

Parameters

FarmAsset $asset: The farm asset.

Return value

string Returns rendered HTML.

1 call to farm_movement_asset_location_markup()
farm_movement_entity_view_alter in modules/farm/farm_movement/farm_movement.module
Implements hook_entity_view_alter().

File

modules/farm/farm_movement/farm_movement.location.inc, line 16
Code for managing the location of assets with movement logs.

Code

function farm_movement_asset_location_markup($asset) {

  // Start an output string.
  $output = '<strong>' . t('Location') . ':</strong> ';

  // Get the asset's location.
  $areas = farm_movement_asset_location($asset);

  // If locations were found, add links to them.
  if (!empty($areas)) {
    $area_links = array();
    foreach ($areas as $area) {
      if (!empty($area->tid)) {
        $area_links[] = l($area->name, 'taxonomy/term/' . $area->tid);
      }
    }
    $output .= implode(', ', $area_links);
  }
  else {
    $output .= 'N/A';
  }

  // Get the asset's most recent movement.
  $log = farm_movement_asset_latest_movement($asset);

  // Load the log's movement field, if it exists.
  if (!empty($log->field_farm_movement[LANGUAGE_NONE][0]['value'])) {
    $movement = field_collection_item_load($log->field_farm_movement[LANGUAGE_NONE][0]['value']);
  }

  // If a geofield exists on the movement, display it.
  if (!empty($movement->field_farm_geofield[LANGUAGE_NONE][0]['geom'])) {

    // Build the geofield map and add it to the page content.
    $field_instance = field_info_instance('field_collection_item', 'field_farm_geofield', 'field_farm_movement');
    $geofield = field_view_field('field_collection_item', $movement, 'field_farm_geofield', $field_instance['display']['default']);
    $geofield['#title'] = t('Geometry');
    $output .= drupal_render($geofield);
  }

  // Return the output markup.
  return $output;
}