User login

Debug a somethnig going weird in someone elses nodeapi presave

Searched words: 
pre-save hook node api

This could be prettier. Do not judge. Especially could be prettier using an IDE.

<?php
/**
* Invoke a hook_nodeapi() operation in all modules.
*
* @param &$node
*   A node object.
* @param $op
*   A string containing the name of the nodeapi operation.
* @param $a3, $a4
*   Arguments to pass on to the hook, after the $node and $op arguments.
* @return
*   The returned value of the invoked hooks.
*/
function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  $return = array();
  foreach (module_implements('nodeapi') as $name) {
if ($op == 'presave') {
// @debug
$v = (array)$node;
drupal_set_message($v['uid']);
}
    $function = $name .'_nodeapi';
if ($op == 'presave') drupal_set_message('blame: ' . $name);   
    $result = $function($node, $op, $a3, $a4);
    if (isset($result) && is_array($result)) {
      $return = array_merge($return, $result);
    }
    else if (isset($result)) {
      $return[] = $result;
    }
if ($op == 'presave') {
// @debug
$v = (array)$node;
drupal_set_message($v['uid']);
}
  }
  return $return;
}
?>

Do this if things are all right and good at the start of a node_save and are not after nodeapi presave is called.
Where the value you are interested in stops showing up, that's the module that is sabotaging you.

Resolution

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or "class="OPTIONS" title="the title".
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.