0
votes

I have added a custom select list to the article/blog form in drupal. I used the select list Field API to create a select list in the hook_form_alter(). I need a way to persist the value chosen for the select list, so when the user edits an article/blog they see the select list with the chosen/persisted value and not the default value. I would appreciate some pointers/suggestions.

Thanks.

1

1 Answers

0
votes

I'm sure there must be a reason you didn't just add a list field, but I would approach this by storing the data in the node itself.

Add a textfield to the node (or whatever is appropriate for your data type), then hide it either within hook_form_alter() by setting the type to hidden, or use a module like field permissions to only allow admins to access that field. (probably more overhead than you need if you're only using it for this one objective)

Then use hook_node_presave() to take the value from your custom select field, and assign it to the hidden text field value.

Once it has been saved once, you can set the default_value of your select list to be the value of the hidden text field.