Skip to content

Instantly share code, notes, and snippets.

@SeanJA
Created August 7, 2012 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeanJA/3285895 to your computer and use it in GitHub Desktop.
Save SeanJA/3285895 to your computer and use it in GitHub Desktop.
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