1

I have a custom field called field_balance in the user account form which is a computed field. It keeps the actual number of coins bought by the current user. That value is supposed to change (increase or decrease) if the user makes particular manipulations on my custom content type which is called Ads.

How do I increase the field's value? By setting up the field.

Setting on field_balance

How do I decrease the value? I am using Rules module to make the field's value decrease. But it doesn't work well yet. This is what I have already tried:

  • The Event: After updating existing content of type Ads
  • The conditions: User has roles "ad editor"
  • The Action : Set a data value. But when I select the field called "site:current-user:field-balance" and hit "Continue", The Data selector turns red and a notification appears.

Here is the illustration:

Add new action screen showing error on data selector

What is it about the computed field that does not continue the rule? Is there any other way to update a computed field with the Rules module?

8
  • Does your computed field allow unlimited values? or only 1 value?
    – No Sssweat
    Commented Sep 11, 2017 at 9:26
  • There is no such think as the number of values on this field type. And my computed field is ment to keep only one value at a time. The calculation (in the field's settings) is always : "$field_b = field_get_items($entity_type, $entity, "field_balance"); $entity_field[0]["value"] = $field_a[0]["value"] + $field_b[0]["value"];". So everytime I add something to the field, the value increases. But when I want to reduce that value (with Rules), that's when things get difficult. Commented Sep 15, 2017 at 10:50
  • Do you really need a computed field? Can't you create an integer field instead and change its value with a Rule every time the entity changes?
    – Jeroen
    Commented Sep 15, 2017 at 16:50
  • I did that. But an integer field will be visible by default when a computed field is just like a variable (so only visible when you need to display it's value). Commented Sep 15, 2017 at 16:53
  • I did try that and try to hide it with the help of conditional_fields (the module). But if hidden in the form, it will also be hidden in the display page. Commented Sep 15, 2017 at 16:54

1 Answer 1

0

I cannot answer your question directly, so I will propose a solution without computed fields for your specific situation. Since your computed field is just a sum of two other fields, it is perhaps easier to replace it with an ordinary integer field Balance and update its value with a simple Rule every time the entity in question changes. In order to allow users to see the field Balance, but deny them access to edit it, you can use the Field Permissions module:

The Field Permissions module allows site administrators to set field-level permissions to edit, view and create fields on any entity.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.