Related Content
Drupal 10: Running Drupal Tests On GitHub Using Workflows
There are a number of different tools that allow you to validate and test a Drupal site. Inspecting your custom code allows you to adhere to coding standards and ensure that you stamp our common coding problems. Adding tests allows you to make certain that the functionality of your Drupal site works correctly.
DrupalCon Lille 2023
This year's DrupalCon Europe was hosted between the 17th and 20th of October, in the French city of Lille. My DrupalCon adventure began early on Monday morning when Chris Maiden picked me up to drive to France via the EuroStar train. We arrived in Lille a little after 4pm, which was really good going for a nearly 400+ mile trip.
Drupal 10: Adding Third Party Settings To Drupal Configuration Entities
Drupal's modular system allows for all kinds of additions to be added to your site through plugins, entities and configuration.
Drupal 10: Adding Custom Permissions To Groups
The Group module in Drupal is a powerful way of collecting together users and content under a single entity.
Drupal 10: Creating A Notification System Using The Message And ECA Modules
Drupal is a great platform to create communities of users where you can allow users to create their own content and interact with each other. One way of keeping users engaged on the site is by letting them know when other users are interacting with content they have created.
Drupal 10: Using Default Content Deploy To Create Testing Content
Performing behavioural testing on a Drupal project allows you to make sure that all of your features work as they should do. This is especially important when you update code as this can introduce bugs that are otherwise time consuming or difficult to spot.
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 philipnorton42 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