0

I use RULES module to create a node (my custom content type) on user creation - so another words every user gets ONE, UNIQUE node when creating account.

Now I would like to have a navigation menu for users, where each user has a link to his own node. How can I achieve this?

EDIT:

Just as example, imagine we are talking about node as user profile. Each user gets one of those nodes on user creation and I want to have a navigation link to edit/view this node.

0

To achieve this I wrote a module, which creates a node on user create. The node has an alias, which is the username. Code below:

function mymodule_user_insert(&$edit, $account, $category) {
    $node = new stdClass();
    $node->type = 'article';
    node_object_prepare($node);

    $node->title = $edit['name'];
    $node->path = array(
        'alias' => $edit['name'],
    );
    $node->uid = $account->uid;
    $node->language = LANGUAGE_NONE;
    node_save($node);
}

Additionally I used MENU_TOKEN module, which allows to input tokens into title and path of menu links. So my new navigation link path is [current-user:name], which links user's article to his profile.

EDIT: Of course in the example I used 'article' as content type, but in practice I use a custom content type. So if you want to use this code, make sure this line:

$node->type = 'article';

is adjusted as per requirements.

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.