3

I would love to see some code samples for this task. I have found this example already http://www.midwesternmac.com/blogs/jeff-geerling/programmatically-adding-or, but it is unclear why that example uses node language for array key, and based on the comment the user removal could be better as well.

1 Answer 1

3

It should be pretty simple:

  1. Load the node you are trying to modify using node_load().
  2. Look for the user referencing field.
  3. Modify the user referencing field.
  4. Save the node using node_save().

I wrote those steps before looking at the example you linked, but after looking at it, it pretty much follows those steps. To answer your question regarding the language: The reason for that is that you are not supposed to hardcode the language key directly. If I am not mistaken, in Drupal 7 this key is something like 'und', but when you use a language on a node this key changes dynamically to something like 'es' or 'en'. If you hardcode the language key, then your code will be translation incompatible. Even if you don't use translation, it is still consider a good Drupal programming practice not to hardcode that language key ;)

If you follow the code that it is given in your link you will be fine.

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.