2014-02-04 09:41:17 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Code for the Farm Log feature.
|
|
|
|
*/
|
|
|
|
|
2015-11-28 19:02:44 +01:00
|
|
|
// Include Features code.
|
2014-02-04 09:41:17 +01:00
|
|
|
include_once 'farm_log.features.inc';
|
2014-11-13 21:53:13 +01:00
|
|
|
|
2015-11-28 19:02:44 +01:00
|
|
|
// Include Asset Location code.
|
|
|
|
include_once 'farm_log.location.inc';
|
|
|
|
|
2014-12-02 19:07:26 +01:00
|
|
|
/**
|
|
|
|
* Implements hook_permission().
|
|
|
|
*/
|
|
|
|
function farm_log_permission() {
|
|
|
|
return array(
|
|
|
|
'view farm logs' => array(
|
|
|
|
'title' => t('View farm logs'),
|
|
|
|
'description' => t('View all farm-related log items.'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-09-08 21:15:55 +02:00
|
|
|
/**
|
2015-10-04 06:06:53 +02:00
|
|
|
* Implements hook_farm_access_perms().
|
2015-09-08 21:15:55 +02:00
|
|
|
*/
|
2015-10-04 06:06:53 +02:00
|
|
|
function farm_log_farm_access_perms($role) {
|
2015-09-08 21:15:55 +02:00
|
|
|
|
2015-10-04 06:06:53 +02:00
|
|
|
// Assemble a list of log types and taxonomies provided by this module.
|
2015-09-08 21:15:55 +02:00
|
|
|
$types = array(
|
|
|
|
'log' => array(
|
|
|
|
'farm_activity',
|
|
|
|
'farm_movement',
|
|
|
|
'farm_observation',
|
|
|
|
),
|
|
|
|
'taxonomy' => array(
|
|
|
|
'farm_observation_types',
|
|
|
|
'farm_priority',
|
|
|
|
'farm_quantity_units',
|
|
|
|
),
|
|
|
|
);
|
2015-10-04 06:06:53 +02:00
|
|
|
|
|
|
|
// Grant different CRUD permissions based on the role.
|
|
|
|
$perms = array();
|
|
|
|
switch ($role) {
|
|
|
|
|
|
|
|
// Farm Manager and Worker
|
|
|
|
case 'Farm Manager':
|
|
|
|
case 'Farm Worker':
|
|
|
|
$perms = farm_access_entity_perms($types);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Farm Viewer
|
|
|
|
case 'Farm Viewer':
|
|
|
|
$perms = farm_access_entity_perms($types, array('view'));
|
|
|
|
break;
|
|
|
|
}
|
2015-09-08 21:15:55 +02:00
|
|
|
|
|
|
|
// Add 'view farm logs' permission.
|
|
|
|
$perms[] = 'view farm logs';
|
|
|
|
|
|
|
|
return $perms;
|
|
|
|
}
|
|
|
|
|
2014-11-26 22:57:00 +01:00
|
|
|
/**
|
2015-03-13 01:02:09 +01:00
|
|
|
* Implements hook_farm_admin_actions().
|
2014-11-26 22:57:00 +01:00
|
|
|
*/
|
2015-03-13 01:02:09 +01:00
|
|
|
function farm_log_farm_admin_actions() {
|
2014-11-26 22:57:00 +01:00
|
|
|
|
2015-03-13 01:02:09 +01:00
|
|
|
// Define farm area actions.
|
2014-11-26 22:57:00 +01:00
|
|
|
$actions = array(
|
2016-02-01 01:28:27 +01:00
|
|
|
'log' => array(
|
|
|
|
'title' => t('Add a log'),
|
|
|
|
'href' => 'log/add',
|
|
|
|
'paths' => array(
|
|
|
|
'farm',
|
|
|
|
),
|
2016-02-01 18:45:04 +01:00
|
|
|
'weight' => 1,
|
2016-02-01 01:28:27 +01:00
|
|
|
),
|
2014-11-29 01:45:46 +01:00
|
|
|
'activity' => array(
|
2014-12-01 01:42:41 +01:00
|
|
|
'title' => t('Add an activity'),
|
2014-11-29 01:45:46 +01:00
|
|
|
'href' => 'log/add/farm_activity',
|
2015-03-14 15:56:52 +01:00
|
|
|
'assets' => array(
|
|
|
|
'all',
|
|
|
|
),
|
|
|
|
'views' => array(
|
|
|
|
'farm_log_activity',
|
|
|
|
),
|
2015-03-13 01:02:09 +01:00
|
|
|
'paths' => array(
|
|
|
|
'taxonomy/term/%',
|
|
|
|
),
|
2014-11-29 01:45:46 +01:00
|
|
|
),
|
2014-11-26 22:57:00 +01:00
|
|
|
'movement' => array(
|
2014-12-01 01:42:41 +01:00
|
|
|
'title' => t('Add a movement'),
|
2014-11-26 22:57:00 +01:00
|
|
|
'href' => 'log/add/farm_movement',
|
2015-03-13 01:02:09 +01:00
|
|
|
'assets' => array(
|
|
|
|
'all',
|
|
|
|
),
|
2015-03-14 15:56:52 +01:00
|
|
|
'views' => array(
|
|
|
|
'farm_log_movement',
|
|
|
|
),
|
2015-09-07 15:49:26 +02:00
|
|
|
'paths' => array(
|
|
|
|
'taxonomy/term/%',
|
|
|
|
),
|
2014-11-26 22:57:00 +01:00
|
|
|
),
|
2015-01-03 21:02:36 +01:00
|
|
|
'observation' => array(
|
|
|
|
'title' => t('Add an observation'),
|
|
|
|
'href' => 'log/add/farm_observation',
|
2015-03-13 01:02:09 +01:00
|
|
|
'assets' => array(
|
|
|
|
'all',
|
|
|
|
),
|
2015-03-14 15:56:52 +01:00
|
|
|
'views' => array(
|
|
|
|
'farm_log_observation',
|
|
|
|
),
|
|
|
|
'paths' => array(
|
2015-05-27 22:31:33 +02:00
|
|
|
'taxonomy/term/%',
|
2015-03-14 15:56:52 +01:00
|
|
|
),
|
2015-01-03 21:02:36 +01:00
|
|
|
),
|
2014-11-26 22:57:00 +01:00
|
|
|
);
|
2015-03-13 01:02:09 +01:00
|
|
|
return $actions;
|
2014-11-26 22:57:00 +01:00
|
|
|
}
|
|
|
|
|
2015-03-21 15:40:03 +01:00
|
|
|
/**
|
|
|
|
* Implements hook_farm_taxonomy_term_view_views().
|
|
|
|
*/
|
|
|
|
function farm_log_farm_taxonomy_term_view_views($term) {
|
|
|
|
|
|
|
|
// If the term is not an area, bail.
|
|
|
|
if ($term->vocabulary_machine_name != 'farm_areas') {
|
2015-04-13 22:49:57 +02:00
|
|
|
return array();
|
2015-03-21 15:40:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return a list of Views to include on Areas.
|
|
|
|
return array(
|
2015-04-10 17:16:22 +02:00
|
|
|
|
2015-04-13 22:49:57 +02:00
|
|
|
// Activities in this area.
|
2015-03-21 15:40:03 +01:00
|
|
|
array(
|
|
|
|
'name' => 'farm_log_activity',
|
|
|
|
'arg' => 2,
|
|
|
|
),
|
2015-04-10 17:16:22 +02:00
|
|
|
|
2015-05-27 22:31:33 +02:00
|
|
|
// Observations in this area.
|
|
|
|
array(
|
|
|
|
'name' => 'farm_log_observation',
|
|
|
|
'arg' => 2,
|
|
|
|
),
|
|
|
|
|
2015-04-13 22:49:57 +02:00
|
|
|
// Area asset history (at the bottom).
|
2015-04-10 17:16:22 +02:00
|
|
|
array(
|
|
|
|
'name' => 'farm_area_assets',
|
|
|
|
'weight' => 100,
|
|
|
|
),
|
2015-03-21 15:40:03 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-12-01 02:30:12 +01:00
|
|
|
/**
|
|
|
|
* Implements hook_farm_area_links().
|
|
|
|
*/
|
|
|
|
function farm_log_farm_area_links($id) {
|
2016-03-07 22:19:42 +01:00
|
|
|
$links = array();
|
|
|
|
|
|
|
|
// Add link to activities.
|
|
|
|
$view = views_get_view('farm_log_activity');
|
|
|
|
$view->preview('default', array($id));
|
|
|
|
if ($view->total_rows > 0) {
|
|
|
|
$links[] = array(
|
|
|
|
'title' => t('Activities') . ': ' . $view->total_rows,
|
2016-03-07 22:17:05 +01:00
|
|
|
'href' => 'farm/logs/activities/all/' . $id,
|
2014-12-01 15:06:09 +01:00
|
|
|
'weight' => -100,
|
2016-03-07 22:19:42 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add link to observations.
|
|
|
|
$view = views_get_view('farm_log_observation');
|
|
|
|
$view->preview('default', array($id));
|
|
|
|
if ($view->total_rows > 0) {
|
|
|
|
$links[] = array(
|
|
|
|
'title' => t('Observations') . ': ' . $view->total_rows,
|
2016-03-07 22:17:05 +01:00
|
|
|
'href' => 'farm/logs/observations/all/' . $id,
|
2015-05-27 22:31:33 +02:00
|
|
|
'weight' => -90,
|
2016-03-07 22:19:42 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $links;
|
2014-12-01 02:30:12 +01:00
|
|
|
}
|
|
|
|
|
2015-10-02 02:46:02 +02:00
|
|
|
/**
|
|
|
|
* Implements hook_entity_presave().
|
|
|
|
*/
|
|
|
|
function farm_log_entity_presave($entity, $type) {
|
|
|
|
|
2015-11-28 19:02:44 +01:00
|
|
|
// When a movement log is saved, populate the Geometry field.
|
|
|
|
if ($type == 'log' && $entity->type == 'farm_movement') {
|
|
|
|
farm_log_movement_geometry_populate($entity);
|
2015-10-02 02:46:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 22:35:54 +01:00
|
|
|
/**
|
2015-04-13 22:49:57 +02:00
|
|
|
* Implements hook_entity_view_alter().
|
2015-02-18 22:35:54 +01:00
|
|
|
*/
|
|
|
|
function farm_log_entity_view_alter(&$build, $type) {
|
|
|
|
|
2015-11-28 19:02:44 +01:00
|
|
|
// If it's not a farm_asset, or if the entity object is not available, bail.
|
|
|
|
if ($type != 'farm_asset' || empty($build['#entity'])) {
|
2015-02-18 22:35:54 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-28 19:02:44 +01:00
|
|
|
// Generate markup to describe the location.
|
|
|
|
$output = farm_log_asset_location_markup($build['#entity']);
|
2015-09-28 23:43:38 +02:00
|
|
|
|
2015-02-18 22:35:54 +01:00
|
|
|
// Add it to the build array.
|
|
|
|
$build['location'] = array(
|
|
|
|
'#markup' => $output,
|
|
|
|
'#weight' => -100,
|
|
|
|
);
|
|
|
|
}
|
2014-12-01 02:30:12 +01:00
|
|
|
|
2014-11-13 21:53:13 +01:00
|
|
|
/**
|
|
|
|
* Implements hook_form_alter().
|
|
|
|
*/
|
|
|
|
function farm_log_form_alter(&$form, &$form_state, $form_id) {
|
|
|
|
|
2015-04-09 04:49:34 +02:00
|
|
|
// If this is a log form...
|
|
|
|
if ($form_id == 'log_form') {
|
2014-11-13 21:53:13 +01:00
|
|
|
|
2015-04-09 04:49:34 +02:00
|
|
|
// If there is an asset(s) reference field.
|
|
|
|
if (!empty($form['field_farm_asset'])) {
|
2015-01-03 21:43:57 +01:00
|
|
|
|
2015-04-09 04:49:34 +02:00
|
|
|
// Alter the form using our helper function.
|
2015-10-02 02:51:40 +02:00
|
|
|
// ($assets are used below for movement logs.)
|
|
|
|
$assets = farm_log_form_prepopulate_asset($form, 'field_farm_asset');
|
2015-04-09 04:49:34 +02:00
|
|
|
}
|
2014-11-19 19:25:22 +01:00
|
|
|
|
2015-04-09 04:49:34 +02:00
|
|
|
// If there is an area(s) reference field...
|
|
|
|
if (!empty($form['field_farm_area'])) {
|
2015-01-03 21:43:57 +01:00
|
|
|
|
2015-04-09 04:49:34 +02:00
|
|
|
// Alter the form with the farm_log helper function.
|
|
|
|
farm_log_form_prepopulate_area($form, 'field_farm_area');
|
2014-11-19 19:25:22 +01:00
|
|
|
}
|
|
|
|
|
2015-05-27 22:32:57 +02:00
|
|
|
// If this is a farm_movement...
|
2015-04-09 04:49:34 +02:00
|
|
|
if ($form['#bundle'] == 'farm_movement') {
|
|
|
|
|
2015-09-07 15:49:26 +02:00
|
|
|
// If the "to" field is empty...
|
|
|
|
if (empty($form['field_farm_move_to'][LANGUAGE_NONE][0]['#default_value'])) {
|
|
|
|
|
|
|
|
// Alter the form with the farm_log helper function.
|
|
|
|
farm_log_form_prepopulate_area($form, 'field_farm_move_to');
|
|
|
|
}
|
|
|
|
|
2015-10-02 02:51:40 +02:00
|
|
|
// If the "from" field is empty, and assets are available...
|
|
|
|
if (empty($form['field_farm_move_from'][LANGUAGE_NONE][0]['#default_value']) && !empty($assets)) {
|
2014-11-13 22:33:33 +01:00
|
|
|
|
2015-04-09 04:49:34 +02:00
|
|
|
// Look up the asset's last location and prepopulate the "from" field.
|
2015-10-02 02:53:45 +02:00
|
|
|
farm_log_prepopulate_movement_from($form['field_farm_move_from'], $assets, TRUE);
|
2014-11-19 19:25:22 +01:00
|
|
|
}
|
|
|
|
}
|
2015-05-27 22:32:57 +02:00
|
|
|
|
|
|
|
// Or, if this is a farm_observation...
|
|
|
|
elseif ($form['#bundle'] == 'farm_observation') {
|
|
|
|
|
|
|
|
// If the observation type field is empty, prepopulate it with "General".
|
|
|
|
if (empty($form['field_farm_observation_type'][LANGUAGE_NONE]['#default_value'])) {
|
|
|
|
$form['field_farm_observation_type'][LANGUAGE_NONE]['#default_value'] = t('General');
|
|
|
|
}
|
|
|
|
}
|
2014-11-19 19:25:22 +01:00
|
|
|
}
|
2015-05-27 17:53:19 +02:00
|
|
|
}
|
|
|
|
|
2014-11-19 19:25:22 +01:00
|
|
|
/**
|
|
|
|
* Helper function for enabling asset prepopulation in log forms.
|
|
|
|
*
|
2015-04-13 22:49:57 +02:00
|
|
|
* @param array $form
|
2014-11-19 19:25:22 +01:00
|
|
|
* The form array to modify, passed by reference.
|
2015-04-13 22:49:57 +02:00
|
|
|
* @param string $field_name
|
2014-11-19 19:25:22 +01:00
|
|
|
* The machine name of the entity reference field that should be populated.
|
|
|
|
*
|
2015-10-02 02:51:40 +02:00
|
|
|
* @return array|bool farm_asset
|
|
|
|
* Returns the asset objects in an array, if found, FALSE otherwise.
|
2014-11-19 19:25:22 +01:00
|
|
|
*/
|
2015-09-11 17:30:03 +02:00
|
|
|
function farm_log_form_prepopulate_asset(array &$form, $field_name = 'field_farm_asset') {
|
2015-09-11 21:01:25 +02:00
|
|
|
|
|
|
|
// If the "farm_asset" GET parameter isn't set, bail.
|
|
|
|
$params = drupal_get_query_parameters();
|
|
|
|
if (empty($params['farm_asset'])) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-10-02 02:51:40 +02:00
|
|
|
// If only a single asset id is passed, convert it to an array.
|
|
|
|
if (!is_array($params['farm_asset'])) {
|
|
|
|
$params['farm_asset'] = array($params['farm_asset']);
|
2015-09-11 21:01:25 +02:00
|
|
|
}
|
|
|
|
|
2015-10-02 02:51:40 +02:00
|
|
|
// Validate that all the asset IDs are valid by loading the assets themselves.
|
|
|
|
$assets = array();
|
|
|
|
foreach($params['farm_asset'] as $asset_id) {
|
|
|
|
|
|
|
|
// Attempt to load the asset.
|
|
|
|
$asset = farm_asset_load($asset_id);
|
|
|
|
|
|
|
|
// If it loaded, add it to the array.
|
|
|
|
if (!empty($asset)) {
|
|
|
|
$assets[] = $asset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there are no assets, bail.
|
|
|
|
if (empty($assets)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-11-19 19:25:22 +01:00
|
|
|
|
2015-09-11 17:30:03 +02:00
|
|
|
// Load the field instance definition.
|
|
|
|
$entity_type = $form['#entity_type'];
|
|
|
|
$bundle = $form['#bundle'];
|
|
|
|
$field_instance = field_info_instance($entity_type, $field_name, $bundle);
|
|
|
|
|
2015-10-02 02:51:40 +02:00
|
|
|
// If the widget type is "radios/checkboxes" or "select list"...
|
|
|
|
if (in_array($field_instance['widget']['type'], array('options_buttons', 'options_select'))) {
|
|
|
|
|
|
|
|
// Build a list of asset ID.
|
|
|
|
$asset_ids = array();
|
|
|
|
foreach ($assets as $asset) {
|
|
|
|
$asset_ids[] = $asset->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use the array of asset IDs as the field's default value.
|
|
|
|
if (empty($form[$field_name][LANGUAGE_NONE]['#default_value'])) {
|
|
|
|
$form[$field_name][LANGUAGE_NONE]['#default_value'] = $asset_ids;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the widget type is "autocomplete" or "autocomplete tags"...
|
|
|
|
elseif (in_array($field_instance['widget']['type'], array('entityreference_autocomplete', 'entityreference_autocomplete_tags'))) {
|
|
|
|
|
|
|
|
// Build a list of asset labels in the format that the widget expects.
|
|
|
|
$asset_labels = array();
|
|
|
|
foreach ($assets as $asset) {
|
|
|
|
$asset_labels[] = entity_label('farm_asset', $asset) . ' (' . $asset->id . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
// For "autocomplete", add each one as a separate field.
|
|
|
|
if ($field_instance['widget']['type'] == 'entityreference_autocomplete') {
|
|
|
|
foreach ($asset_labels as $key => $label) {
|
|
|
|
|
|
|
|
// If the item isn't empty, skip it.
|
|
|
|
if (!empty($form[$field_name][LANGUAGE_NONE][$key]['target_id']['#default_value'])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @todo
|
|
|
|
* This seems to be the easiest way to autopopulate entityreference_autocomplete
|
|
|
|
* widgets, but it is MESSY! If anyone can figure out a better way, I will buy
|
|
|
|
* you a beer.
|
|
|
|
*/
|
|
|
|
// Copy the initial array structure from the first element.
|
|
|
|
$form[$field_name][LANGUAGE_NONE][$key] = $form[$field_name][LANGUAGE_NONE][0];
|
|
|
|
|
|
|
|
// Set the default, delta, and weight values.
|
|
|
|
$form[$field_name][LANGUAGE_NONE][$key]['target_id']['#default_value'] = $label;
|
|
|
|
$form[$field_name][LANGUAGE_NONE][$key]['target_id']['#delta'] = $key;
|
|
|
|
$form[$field_name][LANGUAGE_NONE][$key]['target_id']['#weight'] = $key;
|
|
|
|
|
|
|
|
// Only make the first one required.
|
|
|
|
if ($key > 0) {
|
|
|
|
$form[$field_name][LANGUAGE_NONE][$key]['target_id']['#required'] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$form[$field_name][LANGUAGE_NONE]['#max_delta'] = $key;
|
|
|
|
$form[$field_name][LANGUAGE_NONE][$key]['_weight']['#delta'] = $key;
|
|
|
|
$form[$field_name][LANGUAGE_NONE][$key]['_weight']['#default_value'] = $key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For "autocomplete tags", implode them all into one comma-separated list.
|
|
|
|
elseif ($field_instance['widget']['type'] == 'entityreference_autocomplete_tags') {
|
|
|
|
if (empty($form[$field_name][LANGUAGE_NONE]['#default_value'])) {
|
|
|
|
$form[$field_name][LANGUAGE_NONE]['#default_value'] = implode(', ', $asset_labels);
|
|
|
|
}
|
|
|
|
}
|
2015-04-08 21:49:07 +02:00
|
|
|
}
|
|
|
|
|
2015-10-02 02:51:40 +02:00
|
|
|
// If the widget type is "entity reference view widget"...
|
|
|
|
elseif ($field_instance['widget']['type'] == 'entityreference_view_widget') {
|
|
|
|
|
|
|
|
// Add a set of checkbox form elements, as the entityreference_view_widget
|
|
|
|
// module expects...
|
|
|
|
foreach ($assets as $key => $asset) {
|
|
|
|
|
|
|
|
// If the item isn't empty, skip it.
|
|
|
|
if (!empty($form[$field_name][LANGUAGE_NONE][$key]['target_id'])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the checkbox element.
|
|
|
|
$form[$field_name][LANGUAGE_NONE][$key]['target_id'] = array(
|
|
|
|
'#type' => 'checkbox',
|
|
|
|
'#return_value' => $asset->id,
|
|
|
|
'#value' => $asset->id,
|
|
|
|
'#title_display' => 'after',
|
|
|
|
'#attributes' => array(
|
|
|
|
'checked' => 'checked',
|
|
|
|
),
|
|
|
|
'#title' => entity_label('farm_asset', $asset),
|
|
|
|
);
|
2014-11-13 21:53:13 +01:00
|
|
|
}
|
|
|
|
}
|
2014-11-19 19:25:22 +01:00
|
|
|
|
2015-10-02 02:51:40 +02:00
|
|
|
return $assets;
|
2014-12-01 03:49:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function for enabling area prepopulation in log forms.
|
|
|
|
*
|
2015-04-13 22:49:57 +02:00
|
|
|
* @param array $form
|
2014-12-01 03:49:46 +01:00
|
|
|
* The form array to modify, passed by reference.
|
2015-04-13 22:49:57 +02:00
|
|
|
* @param string $field_name
|
2014-12-01 03:49:46 +01:00
|
|
|
* The machine name of the term reference field that should be populated.
|
|
|
|
*
|
|
|
|
* @return TaxonomyTerm term
|
|
|
|
* Returns the taxonomy term object, if found.
|
|
|
|
*/
|
2015-04-13 22:49:57 +02:00
|
|
|
function farm_log_form_prepopulate_area(array &$form, $field_name = 'field_farm_area') {
|
2014-12-01 03:49:46 +01:00
|
|
|
$area = NULL;
|
|
|
|
|
2015-04-08 21:49:07 +02:00
|
|
|
// Alias for the field's default value.
|
|
|
|
$field_value = &$form[$field_name][LANGUAGE_NONE]['#default_value'];
|
|
|
|
|
2014-12-01 03:49:46 +01:00
|
|
|
// If the "farm_area" query parameter is set...
|
|
|
|
$params = drupal_get_query_parameters();
|
|
|
|
if (!empty($params['farm_area'])) {
|
|
|
|
|
|
|
|
// Verify that the farm_area is valid.
|
|
|
|
$area = taxonomy_term_load($params['farm_area']);
|
|
|
|
if ($area) {
|
|
|
|
|
|
|
|
// Add the area to the form.
|
|
|
|
$form['farm_area'] = array(
|
|
|
|
'#type' => 'value',
|
|
|
|
'#value' => $area,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Prepopulate the area reference field.
|
2015-04-08 21:49:07 +02:00
|
|
|
if (empty($field_value)) {
|
|
|
|
$field_value = entity_label('taxonomy_term', $area);
|
2014-12-01 03:49:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $area;
|
2014-12-22 23:33:34 +01:00
|
|
|
}
|