Skip to content

Instantly share code, notes, and snippets.

@SeanJA
Created Aug 7, 2012
Embed
What would you like to do?
I heard you like switches
<?php
function my_module_nodeapi(&$node, $op, $teaser, $page){
$func = 'my_module_nodeapi_'.$node->type.'_'.$op;
if(function_exists($func)){
$func(&$node, $teaser, $page);
}
}
<?php
function my_module_nodeapi(&$node, $op, $teaser, $page) {
switch ($op) {
case 'view':
switch ($node->type) {
case 'my_node_type':
//do the things
break;
case 'my_second_node_type':
//do the things
break;
}
break;
case 'load':
switch ($node->type) {
case 'my_node_type':
//do the things
break;
case 'my_second_node_type':
//do the things
break;
}
break;
case 'insert':
switch ($node->type) {
case 'my_node_type':
//do the things
break;
case 'my_second_node_type':
//do the things
break;
}
break;
case 'update':
switch ($node->type) {
case 'my_node_type':
//do the things
break;
case 'my_second_node_type':
//do the things
break;
}
break;
case 'delete':
switch ($node->type) {
case 'my_node_type':
//do the things
break;
case 'my_second_node_type':
//do the things
break;
}
break;
case 'load':
switch ($node->type) {
case 'my_node_type':
//do the things
break;
case 'my_second_node_type':
//do the things
break;
}
break;
case 'presave':
switch ($node->type) {
case 'my_node_type':
//do the things
break;
case 'my_second_node_type':
//do the things
break;
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment