I have made a new content type in Drupal 7 in Drupal Admin (not via module). What I want to do is to add a Hook on the insert and update operation. How can this be done when my node type is not created by a module?
Can this be done at all?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI have made a new content type in Drupal 7 in Drupal Admin (not via module). What I want to do is to add a Hook on the insert and update operation. How can this be done when my node type is not created by a module?
Can this be done at all?
You want to create a custom module. Note that nothing stops you from creating content types through the user interface, it is in fact the suggested way to do so nowadays with fields and stuff (instead of using hook_node_info()
)
Node API Hooks contains an overview of all hooks that can be used to interact with nodes at different events like create, view, delete..
Just wanted to add a comment on how I solved it in case anyone else needs it. This function ads a taxonomy term equal to the node title into a vocabulary defined in the function when a new node of your chosen type is inserted:
function node_title_taxonomy_node_insert ($node) {
if ($node->type == '<your node type>'):
// Get vocabulary ID for vocabulary name
$vocabulary_name = "<Vocabulary name>";
// Prepare taxonomy term
$taxonomy_term_name = $node->title;
// Add vocabulary and term
_node_title_taxonomy_add_vocabulary_term($vocabulary_name,$taxonomy_term_name);
endif;
}
Thanks for the help Berdir :)