function farm_log_populate_geometry in farmOS 7
Helper function for populating a log's geometry from an area reference field.
Parameters
Entity $entity: The entity to act upon.
See also
farm_log_entity_movement_presave().
1 call to farm_log_populate_geometry()
- farm_log_entity_presave in modules/
farm/ farm_log/ farm_log.module - Implements hook_entity_presave().
File
- modules/
farm/ farm_log/ farm_log.module, line 433 - Code for the Farm Log feature.
Code
function farm_log_populate_geometry($entity) {
// Define the area field name.
$area_field = 'field_farm_area';
// If the log doesn't have an area reference field, bail.
if (!isset($entity->{$area_field})) {
return;
}
// If a geometry is already defined, bail.
if (!empty($entity->field_farm_geofield[LANGUAGE_NONE][0]['geom'])) {
return;
}
// Load the area(s) referenced by the area reference field.
$area_ids = array();
if (!empty($entity->{$area_field}[LANGUAGE_NONE])) {
foreach ($entity->{$area_field}[LANGUAGE_NONE] as $area_reference) {
if (!empty($area_reference['tid'])) {
$area_ids[] = $area_reference['tid'];
}
}
}
// Extract geometries from the areas.
$geoms = farm_area_extract_geoms($area_ids);
// Populate the geofield.
farm_map_geofield_populate($entity, $geoms);
}