[documentation] [bug] node_validate() is never called
sepeck
drupal-docs at drupal.org
Wed Mar 15 21:14:20 UTC 2006
Issue status update for
http://drupal.org/node/53639
Post a follow up:
http://drupal.org/project/comments/add/53639
Project: Documentation
Version: <none>
Component: Developer Guide
Category: bug reports
Priority: normal
Assigned to: mercmobily
Reported by: mercmobily
Updated by: sepeck
Status: active
Here's the problem. Drupaldocs is not controlled by members of the
documentation team. We may have to setup a seperate project for issues
with api.drupal.org when the api docs are transferred there.
Not sure where to put this issue at this point.
sepeck
Previous comments:
------------------------------------------------------------------------
Sun, 12 Mar 2006 10:55:02 +0000 : mercmobily
Hi,
I developed my own module type, article_node.
I wrote my own node_article_validate(&$node) function:
function node_article_validate(&$node) {
if (!user_load(array('name' => $node->editor_uid_name))) {
form_set_error('editor_uid_name', t('The editor must be a valid
account'));
}
}
...but it wouldn't get called.
I then added this to node.module ("the" node.module which comes with
Drupal):
/** * Perform validation checks on the given node. */
function node_validate($node) {
// Convert the node to an object, if necessary.
$node = (object)$node;
this_does_not_exist(); // SEE THIS! THIS WAS ADDED!
// Make sure the body has the minimum number of words.
[...]
Well, believe it or not, EVERYTHING works absolutely fine! Add a node,
edit it... and no error is given for calling "this_does_not_exist".
I marked it as "critical", because no validation can be really bad...
Merc.
------------------------------------------------------------------------
Sun, 12 Mar 2006 13:32:40 +0000 : markus_petrux
To use hook_validate() you have to implement hook_node_info() too. See
the page.module for an example.
>> node_validate() not being invoked?
Well, I have made the following test.
1) Goto admin/settings/content-types/page
2) Set a minimum of 10 words for page nodes and save.
3) Goto node/add/page, enter a title 'test' and a body 'just 3 words'
I get an error message issued from node_validate().
I'm changing the status of this issue to 'support request' with
'normal' priority. But maybe I didn't got the problem right, so feel
free to correct me if I've been wrong.
------------------------------------------------------------------------
Sun, 12 Mar 2006 14:55:23 +0000 : mercmobily
Hello,
I have most definitely implemented node_info (in my case,
node_article_node_info() ).
The piece of code I provided was only a tiny fraction of my module
(which I will release when it's finished, BTW).
Plus, the issue was marked as critical because you can write *jokes* in
node_validate() in the CORE module node.module - it is never, ever
executed.
As I wrote above, change the core function node.module from:
------------------------
/** * Perform validation checks on the given node. */
function node_validate($node) {
// Convert the node to an object, if necessary.
$node = (object)$node;
// Make sure the body has the minimum number of words.
[...]
------------------------
To:
------------------------
/** * Perform validation checks on the given node. */
function node_validate($node) {
// Convert the node to an object, if necessary.
$node = (object)$node;
knock_knock_who_is_it_its_the_doctor_doctor_who_ah_you_said_it();
// Make sure the body has the minimum number of words.
[...]
-------------------------
Then, you can submit forms in the system - the node_validate is never,
ever called.
I don't know Drupal well enough yet (I've installed it a week ago for
the first time), but I have the feeling that the problem I am having is
related.
I remember seeing a patch to avoid node_validate() being called
twice... maybe that went funny?
Bye,
Merc.
------------------------------------------------------------------------
Sun, 12 Mar 2006 15:28:40 +0000 : markus_petrux
Well, I edited my version (HEAD) of node.module to call a non-defined
function from node_validate() and..
1) Goto node/add/page
2) enter a title 'test' and a body 'hello world'
3) hit 'preview'
I got a blank page with the following:
Fatal error: Call to undefined function: test_a_non_defined_function()
in /path-to-drupal/modules/node.module on line 1608
I my case node_validate() is called.
If you can't see that, hmm... have you checked admin/logs ?
------------------------------------------------------------------------
Mon, 13 Mar 2006 01:52:26 +0000 : mercmobily
OK, you are completely right and I am a complete idiot.
Well... not 100% complete idiot.
I am not sure this is a problem with the "drupal core" - I am leaving
it here just in case it is.
I based my module on node_example.module. Now, I:
* Copied module.example *as is* and put it in "modules". I also created
its table
* I changed it slightly:
-------------------
function node_example_validate(&$node) {
this_does_not_exist(); // I ADDED THIS
if ($node->quantity) {
if (!is_numeric($node->quantity)) {
form_set_error('quantity', t('The quantity must be a number.'));
}
}
---------------------
The node_example_validate hook is never called - I can create
"node_example" node types without any trouble.
Now, there are two possibilities:
* The node_example.module is somehow wrong
* The drupal core is doing something wrong
To be honest, I don't think it's the core - I tested blog.module, and
blog_validate() is indeed called.
However, I think it's worth investigating, because potentially a lot of
people will use module_example.module and will run into the same
issue...!
Thanks a million,
Merc.
------------------------------------------------------------------------
Mon, 13 Mar 2006 02:21:51 +0000 : markus_petrux
Since core is changing everyday, node_example is probably out dated; I
think this issue belongs to the Document project.
In the meantime, try to look at how core modules (maybe page or story)
or some other contrib modules work.
------------------------------------------------------------------------
Mon, 13 Mar 2006 02:35:07 +0000 : mercmobily
Hello,
Well, since the problem seems to be in node_example, I guess it is a
documentation issue.
However, it's very frustrating: there seem to be a 1:1 correspondence
between the functions in page.module and node_example.module, and yet
page_validate() is called, and node_example_validate() isn't.
Any ideas, anybody?
Merc.
------------------------------------------------------------------------
Mon, 13 Mar 2006 04:34:49 +0000 : mercmobily
FOUND IT!!!
The problem is in node_article_form().
Right now, it returns:
return array_merge($form, filter_form($node->format));
This seems to inhibit node_article_validate() - I have no idea why.
If I return:
return $form;
Then the validation happens.
Any idea what filter_form does? And should it be deleted from
node_example?
------------------------------------------------------------------------
Mon, 13 Mar 2006 19:44:34 +0000 : drewish
mercmobily, based on that last bit of code you pasted in, it doesn't
look like you've got a HEAD version of the node_example.module. take a
look around in it and see if it implements hook_nodeapi()'s "'delete
revision" operation. if it doesn't you've got an old version.
i've heard that drupaldocs.org hasn't been updated recently, and that
it's being moved to a different server, so you'll probably have to use
CVS to get the current version. at the time of this posting, this [1]
is the current version.
hopefully that will help fix a couple of your problems.
[1]
http://cvs.drupal.org/viewcvs/drupal/contributions/docs/developer/examples/node_example.module?only_with_tag=HEAD&view=markup
is
------------------------------------------------------------------------
Tue, 14 Mar 2006 08:51:43 +0000 : mercmobily
Hi,
OUCH!
That's really bad. I based my module on:
http://drupaldocs.org/api/head/file/contributions/docs/developer/examples/node_example.module
Whici is ponted to by:
http://drupaldocs.org/api/head
Now... the link you gave me is the direct CVS account. I had assumed
that the two were synchronised! :-|
Merc.
------------------------------------------------------------------------
Tue, 14 Mar 2006 11:34:04 +0000 : mercmobily
Bloody hell guys...
I am slow at programming in PHP and Drupal. But... honestly, I wasted
*hours* because if the synchronisation problem betweeb the link in the
documentation and the "real" CVS.
Please please please fix it. Porting the module from the "oid" style to
the new style is a major pain.
Merc.
More information about the documentation
mailing list