Skip to content

Instantly share code, notes, and snippets.

@didlix
Forked from maartenJacobs/gist:1424084
Created December 2, 2011 17:29
Show Gist options
  • Save didlix/1424088 to your computer and use it in GitHub Desktop.
Save didlix/1424088 to your computer and use it in GitHub Desktop.
Viewing of content type restriction
<?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