Read This Before Creating A New Drupal Node Or Getting A New Node Identifier From Module Code

By | October 20, 2011

Drupal is one of the most popular CMS on web hosting accounts. When you are new to Drupal and  you try to modify the code of a module directly so that you can add some features, In such situations you should be able to create several nodes from a single form. While doing this most of the newbies forget that one should never try to modify a core or make any changes directly to modules. You can either implement changes using hook_ and theme_architecture and if these are not supported then the safest option is to copy the function in which you want to make changes, and override it. This way the changes will remain limited up to your code and won’t affect after you override a module or Drupal core.
There are two ways to create a new Drupal Node or to get a newer Node Identifier. You can select one of the two you depending on your choice.
hook_nodeapi ()
hook_nodeapi() – This hook is not reserved for any node modules, but still it allows changes in modules  which affect on nodes, despite that module defines the node. One can turn off a particular operation of a newly created node and run other function as per requirements. If you want to repeat it when the nodes are saved then you can also use the ‘update’ operation.
hook_form_alter ()
By using ‘hook_form_alter ()’ you can perform many alterations before rendering a form. Another well known user of this hook is for addition of form elements to the node form. When you are altering a node form, at that time the node object is retrieved from $form[‘#node’]. Also remember that ‘hook_form_alter()’ works for all forms and if you want to alter a specific form then you need to use ‘hook_form_FORM_ID_alter()’ this hook.