Closed (fixed)
Project:
Documentation
Component:
Developer Guide
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
12 Oct 2005 at 17:47 UTC
Updated:
7 Jul 2007 at 02:16 UTC
case 'update':
if ($node->moderate && user_access('access submission queue')) {
print theme('box', t('Post queued'), t('The post is queued for approval.
You can check the votes in the <a href="/%queue">submission
queue</a>.', array('%queue' => url('queue'))));
}
elseif ($node->moderate) {
print theme('box', t('Post queued'), t('The post is queued for approval.
The editors will decide whether it should be published.'));
}
else {
print theme('box', t('Post published'), t('The post is published.'));
}
break;
The above code is listed under hook_nodeapi on drupaldocs. But when one attempts to print in a similar fashion using the update case from within a module calling the nodeapi hook, you get a "cannot modify header information..." error.
Upon closer examination, the doc is at fault. The above code proposes methods that are impossible in 4.6.3. It should be changed to drupal_set_message.
Comments
Comment #1
drewish commentedI was going to roll a patch for this but I Just wanted to make sure I understand this. The problem is that
print theme('box', ...)is sending output too early (before a redirect?) and should be replaced bydrupal_set_message()?Comment #2
fool2 commentedThe problem is in the documentation. http://drupaldocs.org/api/4.6/function/hook_nodeapi
Under "code" there is bad code, essentially. Using that code in your own modules will yield the error I described. Instead of print theme('box'....) it should be drupal_set_message which will not output anything until the appropriate time. (The update hook executes before the headers are sent, so this will yield an error if you output at that time)
Comment #3
beginner commentedThe 4.6 API doc is indeed at fault:
http://api.drupal.org/api/4.6/function/hook_nodeapi
but it has been fixed with 4.7 onwards:
http://api.drupal.org/api/4.7/function/hook_nodeapi
http://api.drupal.org/api/5/function/hook_nodeapi
Comment #4
(not verified) commented