1

For clever auth users who know you have a drupal site, they can type in "node/add/whatever" into your site and the page, "Create Content" pops up with all the links to the content that user is allowed to create.

I wish to hide this specific page. I found one way, not too practical, though. You would theme the "page-node-add.tpl.php" to redirect to 404, but then you need to manually add page-add themes for each content type for those links to work. Ugh.

I think the best way is to create some theme function to read if the page title is "Create Content" then redirect to 404.

Does anyone have any insight? Code? Cheers!

  • 1
    Why not set up the Drupal permissions to control which content types people are allowed to use? – Will Martin Jul 10 '11 at 18:54
2

I put this in a comment already, but here are some more detailed instructions on how to set up permissions to restrict access to content types. I assume you are using Drupal 7; if you're still on Drupal 6, the exact sequence of clicks will be different, but the basic approach is the same.

  1. Log in as an administrator.
  2. Click People in the nav bar at the top.
  3. Click the Permissions tab (top right of the People overlay).
  4. Click the Roles sub-tab (immediately below Permissions tab).
  5. Add a new role using the text box at the bottom of the overlay. For example, "editor".
  6. Click the "Permissions" sub-tab immediately to the left of Roles.
  7. Go down the list of permissions and choose which role can do it. For example, if you want any authorized user to be able to pose comments, check the "Post comments" check box in the Authenticated User column. And if you want only editors to be able to post book pages, Check "Post book pages" in the editor column and NOT the Authenticated User column.
  8. Click the "List" tab at the top of the People overlay, next to Permissions.
  9. Find the user accounts of everyone you think should be an editor, and add that role to their account.

If you have a lot of users already, you can add the role en masse by checking the box next to the names you want to grant editorial permission to, and then pick "Add a role to the selected users - editor" from the drop-down box in the Update Options part of the overlay.

  • Yep that's it, restricting access to node creation is what the "create $type content" permissions are made for. – Pierre Buyle Jul 11 '11 at 8:28
0

If, for some reason, you want to allow your users to create node at the API level (using some custom pages) but not from the node/add/$type pages, you can use an hook_menu_alter() implementation to change the required permission to access to pages.

function MODULE_menu_alter(&$items) {
  foreach (node_type_get_types() as $type) {
    $type_url_str = str_replace('_', '-', $type->type);
    $items['node/add/' . $type_url_str]['access callback'] = 'MODULE_node_add_access';
  }
}

function MODULE_node_add_access($op, $type) {
  $access = node_access($op, $type);
  if ($access && $op === 'create') {
    return user_access('access ' . $type . ' content creation page')
  }
  else {
     return $access;
  }
}

function MODULE_permission() {
  $permissions = array();
  foreach (node_type_get_types() as $type) {
    $info = node_type_get_type($type);
    $permissions['access ' . $type . ' content creation page'] = array(
      'title' => t('%type_name: Access content creation page', array('%type_name' => $info->name)
    )
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy