function example_nodeapi in Coder 7
Same name and namespace in other branches
- 7.2 coder_upgrade/tests/old/samples/example.module \example_nodeapi()
Implement hook_nodeapi.
Is there a diagram showing the order of node operations? Example: see comments in hook_node_build_alter. The "form" and "register" operations have been removed. Use hook_form_alter instead.
File
- coder_upgrade/
tests/ old/ samples/ example.module, line 2330
Code
function example_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($op == 'delete') {
$node->nid = 0;
// Do something.
}
elseif ($op == 'prepare translation' && $a3 == 'account') {
$node->title = 'Get rid of the deadwood.';
// Do something.
}
else {
// Why would we have an ELSE in this situation?
$node->body = 'Coder Upgrade is awesome.';
// Do something.
}
switch ($op) {
case 'alter':
// This block becomes example_node_build_alter
break;
case 'delete':
// This block becomes example_node_delete
break;
case 'delete revision':
// This block becomes example_node_revision_delete
break;
case 'insert':
// This block becomes example_node_insert
break;
case 'load':
// This block becomes example_node_load
break;
case 'prepare':
// This block becomes example_node_prepare
break;
case 'prepare translation':
// This block becomes example_node_prepare_translation
break;
case 'print':
// This block becomes example_node_view with $build_mode = 'print'
break;
case 'rss item':
// This block becomes example_node_view with $build_mode = 'rss'
break;
case 'search result':
// This block becomes example_node_search_result
break;
case 'presave':
// This block becomes example_node_presave
break;
case 'update':
// This block becomes example_node_update
break;
case 'update index':
// This block becomes example_node_update_index
break;
case 'validate':
// This block becomes example_node_validate
break;
case 'view':
// This block becomes example_node_view with $build_mode = 'full' by default
break;
case 'presave':
if ($node->nid && $node->moderate) {
// Reset votes when node is updated:
$node->score = 0;
$node->users = '';
$node->votes = 0;
}
break;
case 'insert':
case 'update':
if ($node->moderate && user_access('access submission queue')) {
drupal_set_message(t('The post is queued for approval'));
}
elseif ($node->moderate) {
drupal_set_message(t('The post is queued for approval. The editors will decide whether it should be published.'));
}
break;
case 'view':
$node->content['my_additional_field'] = array(
'#value' => theme('mymodule_my_additional_field', $additional_field),
'#weight' => 10,
);
break;
}
}