Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Eluchel on
I have a custom module that implements hook_node_presave(). I have a field collection item(field_alternative_titles) attached to one of my content types(disease topic), I have a link field (field_alternative_titles_title) that is attached to my field collection item(field_alternative_titles). When I add a node of the disease topic content type, in my custom module I want to grab it's url and title, and populate the field_alternative_titles_title field. I have tried several things, but I haven't been able to figure out how to do that. How can I populate that field in a custom module?
Comments
How I would do it.
How I would do it.
Good luck.
I like cookies!
so doing something like:$node
so doing something like:
Would that work? Would hook_node_presave fill in the rest of the data to create the instance of the field_alternative_titles_title field?
Try it out? :-)
Try it out? :-)
I like cookies!
If you are using field
If you are using field collection, you have to follow this,
I think this will help you.
Use this to populate fields
Hey @vinoth.babu,
In your if statement you are checking if
isset($fc_res->field_alternative_titles_title[LANGUAGE_NONE])
and then pulling a title from the value if it is set. Can I use this same code to populate the field_alternative_titles_title field? Maybe doing something like:Would that populate the field_alternative_titles_title field?
Thank you! I think this is the closest I have gotten to a solution yet! :)