Related Content
Drupal 11: The Queues API
I've talked a lot about the Batch API in Drupal recently, and I've mentioned that it is built upon the Queue API, but I haven't gone any deeper than that. I wrote about the Queues API in Drupal 7, but thought I would bring my understanding up to date.
DrupalCamp Scotland 2024
DrupalCamp Scotland returned after a small hiatus of 5 years on the 25th October 2024 and saw nearly 50 people attend the university of Edinburgh Paterson's Land building for a day of talks and sessions.
Drupal 11: Batch Operations Built Into Drupal
This is the sixth article in a series of articles about the Batch API in Drupal. The Batch API is a system in Drupal that allows data to be processed in small chunks in order to prevent timeout errors or memory problems.
Drupal 11: Adding Operations To Running Batches
This is the fifth article in a series of articles about the Batch API in Drupal. The Batch API is a system in Drupal that allows data to be processed in small chunks in order to prevent timeout errors or memory problems.
Drupal 11: Using The Batch API To Process CSV Files
This is the fourth article in a series of articles about the Batch API in Drupal. The Batch API is a system in Drupal that allows data to be processed in small chunks in order to prevent timeout errors or memory problems.
Drupal 11: Using The Finished State In Batch Processing
This is the third article in a series of articles about the Batch API in Drupal. The Batch API is a system in Drupal that allows data to be processed in small chunks in order to prevent timeout errors or memory problems.
Comments
I'm stumped because, theoretically, the $nid isn't created nor available at the time when the page loads.
I'd like to use it to db_insert into a field belonging to a table different than {node} - - - - so that I can perform joins in future queries
Many thnx for your time and consideration
-Ben
Submitted by mcferren on Mon, 12/05/2011 - 02:24
PermalinkYou are correct. The nid isn't available in the form until the node has been saved, which would mean that the form is in the edit state. In this case the node object is kept in the $form['node']->nid parameter.
What you need is to create a hook that will intercept the information after it is saved. This would probably be hook_insert($node), which gets passed the node information after it has been saved and so contains the nid you want.
Of course, you'll probably want to create another hook (something like hook_load()) that will load the information into the node object that you saved in the previous hook.
I hope that helps :)
Submitted by giHlZp8M8D on Mon, 12/05/2011 - 09:16
PermalinkHi Philip,
Many thnx for your guidance! It definitely opened up doors for me to further research. I took your advice and understand how hook_node_insert will perform what I am looking for. I noticed that hook_insert works so long that I use it in the same module that defines the the node type. However, I am planning on using module [B] to add fields to a form that has been created in module [A] - - module[A].install being where the node type is created & module[B] is where I plan to put the hook_node_insert.
I've been reading about creating node types programatically. In my readings, they recommend creating instances (and the fields they align with) inside the install file.
// Create all the fields we are adding to our content type.
foreach (_node_example_installed_fields() as $field) {
field_create_field($field);
}
// Create all the instances for our fields.
foreach (_node_example_installed_instances() as $instance) {
$instance['entity_type'] = 'node';
$instance['bundle'] = $avatard['type'];
field_create_instance($instance);
}
My question is this:
If I have one module[A] where I create the node type and another module[B] that has a hook_form_alter that adds field(s) to the form_id of the node creation form in module[A] ,,,,
,,,to define the table structure that I need to hook_node_insert into, would I create an additional instance in module[B].install or should I have preplanned (when creating module[A].install) and added those extra instances in module[A].install - - - even though the instances would be orphaned until the hook_form_alter in module[B] comes into play?
Or should I bypass this complexity and just use hook_schema in the .install file of module[B]?
Many thnx for taking the time to help.
-Ben
Submitted by mcferren on Thu, 12/08/2011 - 03:02
PermalinkThank you
Submitted by Anonymous on Sat, 03/31/2012 - 13:10
PermalinkAdd new comment