3

I have posted this question on drupal.org (via a comment titled "field modification triggered by saving action"), but I realized that the thread is more than five years old. So I reproduce here the question made there:

field modification triggered by saving action

I need to modify a field, but this change has to be triggered when saving the term and it depends on the value of another field, let me explain ...

term

  • field 1: filled with options A/B/C
  • field 2: <info>random_name

I save and if value in

  • Field 1 is A, then value in Field 2 must change to "Source: random_name"

  • Field 1 is B, then value in Field 2 must change to "Destination: random_name"

  • Field 1 is C, then value in Field 2 must change to "Product: random_name"

Note that the label <info> is the one that must change.

1 Answer 1

0

You can use the Rules module to get this logic implemented. Have a look at my answer to "How to set the values of some fields depending on the value of a list box?".

The rule shown there uses these fields:

  • a selection list field with machine name field_optionlist (corresponds to your field 1).
  • a text field with machine name field_free_format_text (corresponds to your field 2).

If you adapt the machine names in that rule (in Rules export format) to the names from your 2 fields, should be straight forward to further tune (customize) it to also match the values as in your case.

However, to make this to work with only 1 rule (instead of writing 3 rules, ie one for each possible value of field 1, so one for "A", one for "B" and one for "C"), you also need the "Conditional Rules module. That way you could expand the prototype to say dozens of different possible values. For an example using the Rules Conditional module (for which there is not a lot of docu available), refer to my answer to the question "How to prevent a node being saved when using the Rules module?".

Best practice advise: the more you start using the Rules module, the more you should try to group rules together using the Rules Conditional module. Just to keep the entire set of rules manage-able (eg to have related business logic shown on a single Rule UI screen). A good sample of how easy it is to end up with a lot of rules, is what you can see in the Answers module (current 7.x-4.x-rc2 version):

6
  • He would have to create 3 different rules, 1 for each scenario. Although, if he wants one rule, he could use Conditional Rules module.
    – No Sssweat
    Commented Mar 17, 2016 at 13:30
  • To simply this answer: 1) Add Condition >> Text Comparison >> node:field_name1 >> A. 2) Add Action >> Set a Data Value >> node:field_name2 >> random_name (might have to click switch to direct input mode button)
    – No Sssweat
    Commented Mar 17, 2016 at 13:35
  • @NoSssweat : you're correct (thought that was clear enough from what's written in the last parg of my other answer). But let me refine my answer here with yes or no using/requiring Conditional rules. BTW: I more and more try to group many rules together these days using the extra module. Just to keep them manage-able. Commented Mar 17, 2016 at 13:38
  • Thanks for your answer @Pierre.Vriens, I'm a little bit lost though, trying to follow you I have done this: 1. Create the Rule PCHRule. 2. Add triggering event: After updating an existing term of vocabulary A. 3 Add condition (on the original question I was using not real data, now I will use it) Text comparison; term:field-relation contains "Child"..... Until here, because I can't figure out what to put in action to repalce in term: field_entrada <p>the_term</p> by <ul>the_term</ul> .... thanks again Commented Mar 18, 2016 at 16:42
  • I see now that next step is set a Switch, I selected Data to match cases against, and term:field-entrada:value in the data selector, I'm not suere about this step and I dont know how to finish it.... Commented Mar 18, 2016 at 21:31

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.