2

I don't want to show "node/add" in my url "node/add/my_node_type", instead I want to have "adding/my_node_type". Is there a simple way to hide "node/add" but not loose those args? I want to have "node/add/my_node_type" functionality after hitting "adding/my_node_type".

I can't see form add or form edit patterns in path so I think it is not so easy...

Of course after that I will need "node/%/edit" to be "editing/%"...

3 Answers 3

3

I didn't test this code, but if I'm not mistaken, it should be as simple as doing this in a custom module:

function YOUR_MODULE_NAME_menu_alter(&$items) {
  $items['adding/my-node-type'] = $items['node/add/my-node-type'];
  unset($items['node/add/my-node-type']);
}

Something similar could be done for the editing path.

1
  • unset did what I want. I thought that it's not working, cause I forgot to rebuild cache... Commented Mar 16, 2012 at 20:45
2

I would do this like so:

create a new module and in this module declare:

function YOUR_MODULE_NAME_menu_alter(&$items) {
  $items['node/add/your-content-type-name']['page-callback'] = 'drupal_not_found';
}

this will override default page callback for your content type and will return 404 page

Then declare pages you need:

function YOUR_MODULE_NAME_menu() {
   $items = array();
   $items['adding/your-content-type-name'] = array(
     'title' => 'Add new your content type name instance',
     'page callback' => 'your_content_type_name_page_callback',
     'type' => MENU_NORMAL_ITEM,
     'access callback' => TRUE // or whatever you think the access callback should be for this content type
   );
   $items['editing/%'] = array(
     'title' => 'Edit your content type name instance',
     'page callback' => 'your_content_type_name_page_callback',
     'page arguments' => array(2),
     'type' => MENU_NORMAL_ITEM,
     'access callback' => TRUE // or whatever you think the access callback should be for this content type
   );
}

Declare a callback that will be serving the node edit form:

function your_content_type_name_page_callback($nid = FALSE) {
   $node = node_load($nid);
   if($node) {
     if($node->type == 'your_content_type_name') {
       $form = drupal_get_form('your_content_type_name_node_form', $node);
       return drupal_render($form);
     }
   }
   return drupal_not_found();
}

I did pretty much similar task in one of my previous projects, so I am sure this approach will work out. May be there are other ways to accomplish what you are after.

2
  • In D7 $node = node_load($nid) in function your_content_type_name_page_callback can be ommited with $items['editing/%node'] = ... but I'm getting error while drupal_get_form is executed. Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'node_form' not found or invalid function name w drupal_retrieve_form(). It looks like node_form is not accessible inside. Commented Mar 14, 2012 at 14:09
  • your_content_type_name_page_callback seems not right for new content, as when there is no $nid, function will just go to page not found, right?
    – Blissful
    Commented Aug 7, 2015 at 15:15
2

I didn't expect, but I can simply make path alias from node/add/my_node_type to whatever/i/need. Just one click here http://www.example.com/admin/config/search/path/add. No coding, no custom module. All I have to check is how about args - theoretically 'node/add/my_node_type' (3 args path) can be aliased to 'whatever' (looks like 1 arg, but is it?) or 'what/ever/and/ever' (looks like 4 args).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.