Executing custom code.

sime's picture
public
sime - Wed, 2006-11-15 23:04

I created a new node type (the old-fashioned way). Now I'm playing with CCK, seeing what it takes to re-create this node.

Now, say that I have a piece of custom code, and I want it to run in one of the hooks/handlers, eg. an extra bit of validation, or some form_alter on the node_form. What would be considered "best practice" to implement this piece of code? In reality, do I need to hard-code this logic into a simple node module, and then use CCK to extend the fields as I require?

I imagined another tab in the CCK creation, where I could select a handler, and then submit php code that would be executed at that point. I had a little look in the issues queue regarding this, I don't think there was anything there, or maybe my search terms are wrong...

I'd love some ideas on best practice for this type of thing. Thanks


own module

moshe weitzman's picture
moshe weitzman - Thu, 2006-11-16 02:13

i suggest creating a module that is named same as your site and in there, using hook_nodeapi() for the custom validation and such. we should do better, but noone is working on this that i know of.


That confirms that I've

sime's picture
sime - Thu, 2006-11-16 04:23

That confirms that I've mostly got the right idea. Thanks.


It seems like you're doing

ultimike@drupal.org's picture
ultimike@drupal.org - Wed, 2007-01-03 17:39

It seems like you're doing (or have done) what I'm trying to figure out how to do...

I have a custom content type and I need to call a custom validation routine to it. The content type using location information (lat/long) and I need to confirm that there are no other existing locations with 5 miles of the entered lat/lon.

Any chance you'd be willing to post some sample code to get me started? I don't need help with the actual validation routine - I'm just unsure on how to get started with creating a new module and using hook_nodeapi to call my custom validation code.

-mike