The node api is an excellant interface to be able to extend any type of node. When I was implementing the nodeapi into filestore2 to allow a fileupload to be added to any node I found that there was 2 areas that were missing, which stopped me from getting this working. The main reason that I couldn't get filestore to add to another node is because the $param and thus the form could not be changed.
* updating of $param
* inserting extra fields into $node at time of load.
Attached is a patch that adds 2 extra node api's "param" and "load"
The param node api work differently from the normal node as the normal node the $param field is referenced where as in this the new value for $param is returned and merged.
Comment | File | Size | Author |
---|---|---|---|
#9 | nodeapi_1.patch | 3.1 KB | JonBob |
#8 | nodeapi_0.patch | 2.59 KB | JonBob |
#7 | nodeapi.patch | 2.58 KB | JonBob |
0166.HEAD.gordon.form-param_and_load_nodeapi.patch | 1.09 KB | gordon | |
Comments
Comment #1
matt westgate CreditAttribution: matt westgate commented+1 for the nodeapi load hook. Currently in the ecommerce package I have to make duplicate queries to the database. With this hook, all my hacking would disappear and the product module would become an elegant solution.
Comment #2
skip CreditAttribution: skip commented+1
Seems silly to add a file API and not be able to change the form's encoding type...
Comment #3
Dries CreditAttribution: Dries commentedAFAIK the node system invokes the
_load()
hook when a node is being loaded. Why can't that be used? Or, can't we remove the_load()
hook and integrate with the nodeapi as done in your patch?I don't quite understand what the 'form param' stuff does. Can you provide some more details, and maybe a concrete example?
Comment #4
nedjoThis has also been an issue for me when working with the node_image module. nodeapi can add fields to a node add/edit form; but if one of those fields is of type "file", it won't work, since the form it's contained in doesn't have the correct enctype setting (which needs to be "multipart/form-data" for the file upload to work).
What is needed is a way of updating the parameters of the form. I've used the workaroud of patching the node.module, adding the following lines:
+ if(module_exist("node_image") && variable_get("node_image_fields", 0)) {
+ $param['options']['enctype'] = 'multipart/form-data';
+ }
Adding the ability to update the $param variable through nodeapi would solve this problem--so I'm happy to see this patch.
Comment #5
gordon CreditAttribution: gordon commentedDries: Yes the node does involve the _load() function, but only for the current node type, ie story node type will call story_load(). but no others will be called. If you have additional data in that you have stored using the nodeapi then the best place to add this information to the node is at the time of the _load().
Comment #6
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedThe patch still applies. Dries why not apply it?
Comment #7
JonBob CreditAttribution: JonBob commentedI've updated the patch to include "view" in addition to "load" and "form param." This hook allows modules to modify the $node object before viewing; I will use it to do some clever menu magic in taxonomy_menu once this patch goes in. This takes care of all of the instances where nodeapi can't do what normal node hooks can, with the exception of _access(), which needs to be taken care of in a different fashion (the whole node-level permissions issue) and can't be a hook.
Comment #8
JonBob CreditAttribution: JonBob commentedOops. Wrong file version.
Comment #9
JonBob CreditAttribution: JonBob commentedThis update patches node_invoke_nodeapi() to be able to pass two parameters, so that client modules can get the values of $main and $page.
Comment #10
Dries CreditAttribution: Dries commentedCommitted to HEAD. Thanks.
Comment #11
(not verified) CreditAttribution: commented