function farm_log_populate_owner in farmOS 7
Helper function for populating a log's owner field.
Parameters
Entity $entity: The entity to act upon.
$account: Optionally the user account to assign the log to.
See also
farm_log_entity_movement_presave().
1 call to farm_log_populate_owner()
- 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 402 - Code for the Farm Log feature.
Code
function farm_log_populate_owner($entity, $account = NULL) {
// If the log already has an owner, bail.
if (!empty($entity->field_farm_log_owner[LANGUAGE_NONE][0]['target_id'])) {
return;
}
// Get the log owner ID, either from the $account passed in, or from the
// currently authenticated user.
if (!empty($account->uid)) {
$uid = $account->uid;
}
else {
global $user;
$uid = $user->uid;
}
// If we have a user id, assign it as the log owner.
if (!empty($uid)) {
$entity->field_farm_log_owner[LANGUAGE_NONE][] = array(
'target_id' => $uid,
);
}
}