1

I am trying to build a questionnaire that simply replaces (alters) the label of a list field. I am doing so by replacing a token from views (embed) and implementing hook_form_alter() in a separate module.

How can I save that value and write it to the database? I am using an Entity form and a list-field.

This is the snippet I am struggling with, found on Store token replacement values in the database rather than tokens themselves.

function question_to_label_node_presave($node) {
  if ($node->type == 'page') {
    $replaced_text =  token_replace($node->field_question['und'][0]['value']);
    $node->field_question['und'][0]['value'] = $replaced_text;
  }
}

I am currently trying to run this in a custom module, but I cannot find the right content type for the Entity form. I am using the Devel module to find the right array value.

1
  • Hi and welcome to Drupal Answers. Could you please make your question clearer? What is a "select or other"-field? Which entity form? Please share your code.
    – Wtower
    Dec 29 '14 at 14:50
0

I´ve solved it by using a token, and placed that token (from a view) in a hidden field in that form - thus saving that value.

The same token generated from views - I used to alter the label for that question with "hook_alter_form".

A kind of non programmatically way of solving the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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