0

Is it possible to make "Edit link" field as a menu. On my site one user can create only node and I have a page view which displays the node the user logged on has created. This views has a "Edit link" field so that the user can jump to node edit page from this view page.

However I want to have a menu or tab that can directly link to the node edit page of the node the logged in user has created. It should a menu or a tab that says "edit my node" and the user can directly jump to the node edit page without visiting the page views.

0

Menu items in Drupal are cached, so you cannot make them dynamic. I recommend that you do like the user module in Drupal core does for the /user path.

First, create a custom module. In your custom module, implement hook_menu like this:

$items['my-page'] = array(
  'title' => 'My page', 
  'page callback' => 'edit_my_page', 
  'access callback' => TRUE, 
  'type' => MENU_CALLBACK, 
);

This will link the url example.com/my-page to the view_my_page() function. The view_my_page function could look like this (similar to user_page()):

function edit_my_page() {
  global $user;
  $my_nid = 0;

  // Write your own code here to retrieve the Node ID for the
  // current user and store the Node ID in $my_nid.

  if ($my_nid) {
    menu_set_active_item('node/' . $my_nid . '/edit');
    return menu_execute_active_handler();
  }
  else {
    return drupal_get_form('user_login');
  }
}

Now, when a user navigates to example.com/my-page, Drupal will serve the correct node edit page.

  • Thank you very much.This looks very helpful but unfortunately This seems to be a bit over my head as I'm not really a coder. I was wishing to implement this function with an easier way.. – chinita7 Nov 21 '11 at 15:06
  • In that case, I need to ask you: the content type of which users can only create one node, is it some kind of user profile? Because in that case, you could consider switching to the Content Profile module. It allows a one-node-per-user setup like you describe, and integrates with the user account page to make the profile easy to find and edit. – marcvangend Nov 21 '11 at 15:31
  • Yes,You have a very good guess. The node is for user profile. Thanks for your input.It looks like Content Profile is the ideal solution. I should have considered it before started building my site. Now I'll start looking up if I can shift the whole structure of my site. Thanks again it was really helpful. – chinita7 Nov 23 '11 at 18:41
  • If I remember correctly, content profile allows you to mark an existing content type as profile node. Good luck building your site! – marcvangend Nov 23 '11 at 20:17
  • Thanks. I could successfully convert my node type to profile content type and now working as I wanted :) – chinita7 Dec 19 '11 at 15:40
0

I'm a bit confused, because your question sounds like a basic Drupal feature that has been around for years: tabs with "local tasks" as they are called. Here is a screenshot from a Drupal 7 site, without any extra modules:

a simple node in a default Drupal 7 installation

If I understand correctly, the 'Edit' tab is what you are looking for... Or isn't that what you need?

  • Thanks for your response. Looks like my explanation didn't really describe what I need. I'm using node limit number module so that only one node can be created per user. And then I would like to have a menu item linked to the edit page of only the "node created by the currently logged-in user" which means I probably need a dynamic URL something like node/%/edit. Or if the default drupal tab can do this I would like to have the tab on the user page like user/%/ Thanks. – chinita7 Nov 21 '11 at 10:01
  • Sorry I forgot to mention that I'm on Drupal6 – chinita7 Nov 21 '11 at 10:08

Your Answer

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

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