Created
December 2, 2011 17:28
-
-
Save maartenJacobs/1424084 to your computer and use it in GitHub Desktop.
Viewing of content type restriction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_menu_alter(). | |
*/ | |
function module_menu_alter(&$items) { | |
$old_callback = $items['node/%node']['access callback']; | |
$old_args = $items['node/%node']['access arguments']; | |
// Overrides the access callback to remove access to note content | |
$items['node/%node']['access callback'] = '_note_node_view_access'; | |
$items['node/%node']['access arguments'] = array( | |
$old_callback, | |
$old_args | |
); | |
} | |
/** | |
* Restricts access to note content | |
* | |
* @param string $old_callback | |
* @param string $old_args | |
* @return boolean | |
* @author Maarten Jacobs | |
*/ | |
function _note_node_view_access($old_callback, $old_args) { | |
$nid = arg($old_args[1]); | |
$node = node_load($nid); | |
$old_args[1] = $node; | |
if ($node->type == 'note') { | |
// Restrict access for notes | |
return false; | |
} else { | |
return $old_callback($old_args[0], $old_args[1], $old_args[2]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment