I used Drupal 7 computed fields to calculate weight loss. This is what I current have. Which works in a sense but only where the user inputs their initial weight and subtracts their current weight to track the total weight loss at the time of the input. But I need it to reference their initial weight from their user profile so that they only have to enter their current weight. One step process versus having to always enter the data that already exists. How can I achieve this?
Current Code which works great but two fields have to be filled in. Needs to reference field in user profile.
$entity_field['value'] = ($entity->field_iweight['und']['value']) - ($entity->field_current_weight_['und']['value']);
$user object to access the logged in user.
global $user; $account = user_load($user->uid);
Now you can use
$account->field_iweight['und']['value'] (just an example) to access the weight or any other field from the user profile.
<?php global $user; $account = user_load($user->uid); $entity_field['value'] = $account->field_iweight['und']['value'] - $entity->field_current_weight['und']['value']; ?>
Answered by Jayaram on December 15, 2020
1 Asked on December 4, 2020 by miststudent2011
1 Asked on December 3, 2020 by vaibhav-rana
1 Asked on November 30, 2020 by rick1
1 Asked on November 29, 2020 by alaa-haddad
1 Asked on November 18, 2020 by hiranya-sarma
1 Asked on November 13, 2020 by paul-h
2 Asked on October 21, 2020 by wbeasley
1 Asked on October 9, 2020 by sivaji
1 Asked on October 4, 2020 by anders-wallenquist
1 Asked on October 1, 2020 by travis-miller
1 Asked on October 1, 2020 by user3686276
0 Asked on September 13, 2020 by hendrik-kaiser
Get help from others!