Wednesday 30 May 2012

Create Drupal 7 biblio nodes programatically

The biblio module for Drupal is almost certainly essential for anyone trying to use Drupal as a platform for doing science. It is a large module with lots of functionality but parts of it are pretty badly documented (that is: you can read through the code but just Googling might not throw up what you need).

 The first issue - how to create a biblio node programatically (that is: in code).


Some things to note:

1) You must set the type of the biblio you wish to make (Journal Article, Book chapter, etc) before the call to node_object_prepare().

2) To set the authors you must set $node->contributors as an array (like that above) and also call biblio_insert_contributors($node).

The above example sets only a fairly minimal  number of the biblio fields, but any of the biblio fields may be set using this method.

The field 'start page' in biblio entries is for some reason stored in the field biblio_section (that's not an error in the code above)l.

ShareThis

Copyright