How can i hide menu if the node is created.
How can i hide menu if the node is created. let me make it more clear.
i have a menu called [upload images] it allows users to upload multi images per node but every user can only create one node. So if the user click first time on [upload images] he will be sent to create node upload images page. but if he click second time after creating upload image node then he will get drupal error msg. i have two questions
1) how can i hide menu item after node is created.
2) Or how can redirect the user (who has already created the node) to node edit page when he click on menu [upload images)
I couldn't find any module for it. I think this can be easily achieved by writing some PHP but unfortunately i am not a programmer.
Thanks in advance
regards
Kaay

:(....??
:(....??
Options
There should be several other solutions as well (assuming the users are authenticated), e.g.:
Change the permission of the user not to be able to create another page after the node is created.
Or
Create a toggle-variable for each user and check if it is true or not. If the node is created, then the toggle will be true and he will not be able to see the menu or be able to create another page.
Or
Use a CCK field where the user must enter a specific information, then check if the field is filled, then disable the permission, etc.
sorry these are only suggestions and not solutions.
Thanks for the
Thanks for the Suggestions
Actually this is what I did but I don't know how to hide the menu item [image upload] so if the user click on the menu item [image upload] after creating the image upload node, he/she will get the error message, which i don't like but what i would prefer is if user click on the menu item [image upload] after creating the one and only image upload node then he/she should be redirected to their image_upload node edit. And i don't know how to achieve this.
And your other suggestions is beyond my mental level in fact the first one too but i think this one i can do it with the help of some expert in this forum.
Thanks
_
You should be able to add logic to the display of the menu item by using hook_menu_alter in a little custom module.
_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.
Thanks WorldFallz for the
Thanks WorldFallz for the reply. I will give it a try (hook_menu_alter) and get back to you if I need any further assistance. thanks
hi I am sorry i did try to
hi
I am sorry i did try to use hook but don't really know how to apply:
<?phpfunction hook_menu_alter(&$items) {
// Example - disable the page at node/add
$items['node/add']['access callback'] = FALSE;
}
?>
Should I paste this snippet on templete.php or do i need to do more to make it work. sorry if my question sounds very dumb
_
Nope-- hooks need to go in a module. Create a little custom module for it. You'll need to do something like:
<?phpfunction mymodule_menu_alter(&$items) {
global $user;
$result = db_query("SELECT COUNT(n.nid) FROM {node} n WHERE n.uid = %d AND n.type = 'content_type'", $user->uid);
if ($result > 0) {
$items['node/add/content_type']['access callback'] = FALSE;
}
}
?>
Totally untested and probably more pseudo than code but you get the idea.
_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.
Thanks WorldFallz it looks
Thanks WorldFallz it looks good. I will try it and let you know whatever the outcome. Thanks alot.
Hi I just created the module
Hi
I just created the module and tested it. image upload menu item got disappeared. I deleted node to see if menu become visible but it didn't.
let me explain what i did with you code:
i created a file called uturn.module and uturn.info put both files into the folder called uturn, uploaded on the server, activated
I replaced:
<?phpfunction uturn_menu_alter(&$items) {
global $user;
$result = db_query("SELECT COUNT(n.nid) FROM {node} n WHERE n.uid = %d AND n.type = 'images'", $user->uid);
if ($result > 0) {
$items['node/add/images']['access callback'] = FALSE;
}
}
?>
Please check it
Thanks for the support
_
hmmm.... try this:
<?phpfunction uturn_menu_alter(&$items) {
global $user;
$result = db_result(db_query("SELECT COUNT(n.nid) FROM {node} n WHERE n.uid = %d AND n.type = 'images'", $user->uid));
if ($result > 0) {
$items['node/add/images']['access callback'] = FALSE;
}
}
?>
_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.
Thanks for the reply. I am
Thanks for the reply. I am afraid there isn't any change in the problem after replacing your updated code.
what i did:
1. replace the new code to the old one.
2. clear cache
3. run update.php
menu item image upload is still not visible
_
I tested the query so I know it works properly (ie returns the number of nodes created by the logged in user of the specific content type). I'm not sure why the menu isn't behaving as expected. Maybe try one of the node quota modules?
_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.
thanks. since you have tested
thanks. since you have tested the code then there is definitely something isn't right at my side. let me check my content type and settings....ummmh!!!???..... I forgot :) !! how and what i did to stop user to create more than one node ...hhmmm... give me little time I get back to you. Thanks
Hi WorldFallz What node
Hi WorldFallz
What node limit module did you use when you tested the code. Since I reinstalled the "node limit" module, menu item [image uplaod] is not hiding but if you click on the menu it shows "ACCESS DENIED" page, now I cannot even create one node. I also check the node limit setting it allows one node. if I turn off your code it allows me to create node but [image upload] button is also visible which might confuse those users who have already created the node and get "ACCESS DENIED" page when the click second time.
I did also try Module called "Node Limit Number" but no success. Which code did you test, cause iam using your last updated code. What you reckon? Thanks
one question.
What if we redirect the users to the "images/edit" who already created the node when the click on [image upload] button. eg.
MY FANTASY CODE
" onclick button [image upload] if the user has not created the node (images) send him/her to "images/add else %user/images/edit"
Just an idea. for me hiding menu item or redirecting either of them will solve my problem. you suggest which one is simpler and easy
thanks for your time and support
_
I don't have any node limit modules installed-- i was just trying to turn off a menu item so there shouldn't be any need for one. I just thought one of them might work this way.
If you want to try the redirect solution you should be able to do this with the http://drupal.org/project/rules module.
_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.
Just a quick update, I did
Just a quick update, I did post my issue in the Rule's group 4 days ago to know if rule is the right choice for my problem. Up till now I haven't received any reply. Thanks.
Rules plus Node_Limit_Number work to limit nodes by role
I think I found an answer to kaay's original problem, which was to limit the number of nodes of a certain type by user or by user role. The Rules module in combination with the recently revamped Node Limit Number module can be used to limit number of nodes posted by a user by role.
See this thread for the more info:
http://groups.drupal.org/node/29536