Hello all,
Let's i want to display or not display a menu item depending on some property of the logged in user. E.g. when my user has selected a project (i.e. a reference to the project can be found through the user) i want to display a menu item "my project", if not i want to display a different menu item "available projects". How do i do this? Context? Rules? Menu hooks?
Any ideas?
Best,
Toon
You could make two blocks, put them in the same place and assign visibility settings based on role. There are many options, though.
Joel
From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of toon severijns Sent: Tuesday, June 07, 2011 1:01 PM To: support@drupal.org Subject: [support] Dynamically display menu items?
Hello all,
Let's i want to display or not display a menu item depending on some property of the logged in user. E.g. when my user has selected a project (i.e. a reference to the project can be found through the user) i want to display a menu item "my project", if not i want to display a different menu item "available projects". How do i do this? Context? Rules? Menu hooks?
Any ideas?
Best,
Toon
If it were me, I'd use Views and detect the User based on role and probably use Custom Field module for PHP and do all sorts of tests in there. Since it's a block, though, arguments aren't passed, so you could do a Default argument from PHP and do all sorts of fun PHP code in there, so you wouldn't need an additional module.
Or you could assign a role using a Rule, or have the User based on an argument (again, default argument, Current Logged in User), and use Empty Text to show a different menu based on the existence of that project.
Actually, I kinda like that last idea...
Joel
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Joel Willers Sent: Tuesday, June 07, 2011 1:03 PM To: support@drupal.org Subject: Re: [support] Dynamically display menu items?
You could make two blocks, put them in the same place and assign visibility settings based on role. There are many options, though.
Joel
From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of toon severijns Sent: Tuesday, June 07, 2011 1:01 PM To: support@drupal.org Subject: [support] Dynamically display menu items?
Hello all,
Let's i want to display or not display a menu item depending on some property of the logged in user. E.g. when my user has selected a project (i.e. a reference to the project can be found through the user) i want to display a menu item "my project", if not i want to display a different menu item "available projects". How do i do this? Context? Rules? Menu hooks?
Any ideas?
Best,
Toon
Hey Joel, thank you so much! I think i could do it if i would be able to load the currently logged in user in the "Show if the following PHP code returns TRUE" box of the menu block. Can i do that? How?
Alternatively, could you elaborate a bit on your last suggestion please?
Best,
Toon
On Tue, Jun 7, 2011 at 8:17 PM, Joel Willers joel.willers@sigler.comwrote:
If it were me, I'd use Views and detect the User based on role and probably use Custom Field module for PHP and do all sorts of tests in there. Since it's a block, though, arguments aren't passed, so you could do a Default argument from PHP and do all sorts of fun PHP code in there, so you wouldn't need an additional module.
Or you could assign a role using a Rule, or have the User based on an argument (again, default argument, Current Logged in User), and use Empty Text to show a different menu based on the existence of that project.
Actually, I kinda like that last idea...
Joel
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Joel Willers Sent: Tuesday, June 07, 2011 1:03 PM To: support@drupal.org Subject: Re: [support] Dynamically display menu items?
You could make two blocks, put them in the same place and assign visibility settings based on role. There are many options, though.
Joel
From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of toon severijns Sent: Tuesday, June 07, 2011 1:01 PM To: support@drupal.org Subject: [support] Dynamically display menu items?
Hello all,
Let's i want to display or not display a menu item depending on some property of the logged in user. E.g. when my user has selected a project (i.e. a reference to the project can be found through the user) i want to display a menu item "my project", if not i want to display a different menu item "available projects". How do i do this? Context? Rules? Menu hooks?
Any ideas?
Best,
Toon
[ Drupal support list | http://lists.drupal.org/ ]
[ Drupal support list | http://lists.drupal.org/ ]
For your PHP suggestion, you would use global $user and detect the user role, but you wouldn't be able to easily use this for detecting if they have a project.
For my suggestion, you can use the content type Project (I don't know your configuration, so I'm making some general assumptions), and let's say it has a user reference called field_project_user. You would set that as an argument, and in the section for what to do if there is no argument, you set a default argument as logged in user. Then you set a filter for node:type = Project.
If there is no project for that user, then the View doesn't fire, so you create the menu in Empty Text area. So one menu could be in Global:custom text, and the other in Empty Text.
Similar arguments can be used for many user fields, so play around with them. If you give me more specifics, I might be able to send you more explanation, but really, that should be enough for you to create it.
Joel
Hey Joel, thank you so much! I think i could do it if i would be able to load the currently logged in user in the "Show if the following PHP code returns TRUE" box of the menu block. Can i do that? How?
Alternatively, could you elaborate a bit on your last suggestion please?
Best,
Toon
If it were me, I'd use Views and detect the User based on role and probably use Custom Field module for PHP and do all sorts of tests in there. Since it's a block, though, arguments aren't passed, so you could do a Default argument from PHP and do all sorts of fun PHP code in there, so you wouldn't need an additional module.
Or you could assign a role using a Rule, or have the User based on an argument (again, default argument, Current Logged in User), and use Empty Text to show a different menu based on the existence of that project.
Actually, I kinda like that last idea...
Joel
You could make two blocks, put them in the same place and assign visibility settings based on role. There are many options, though.
Joel
Hello all,
Let's i want to display or not display a menu item depending on some property of the logged in user. E.g. when my user has selected a project (i.e. a reference to the project can be found through the user) i want to display a menu item "my project", if not i want to display a different menu item "available projects". How do i do this? Context? Rules? Menu hooks?
Any ideas?
Best,
Toon
Actually, to make it a bit more complex: there is no user reference field. The project is flagged by a certain user. This is used in the view "my_projects" as a relationship "*Flags: student_selected* by current user". Is there a way to still do what you described below? The only arguments that seem to be available to add are "Flags: Content ID" and "Flags: Flagged time". Or do i somehow have to create the user reference when flagging (through Rules)?
Thank you so much for your help already!
Best,
Toon
On Tue, Jun 7, 2011 at 8:59 PM, Joel Willers joel.willers@sigler.comwrote:
For your PHP suggestion, you would use global $user and detect the user role, but you wouldn't be able to easily use this for detecting if they have a project.
For my suggestion, you can use the content type Project (I don't know your configuration, so I'm making some general assumptions), and let's say it has a user reference called field_project_user. You would set that as an argument, and in the section for what to do if there is no argument, you set a default argument as logged in user. Then you set a filter for node:type = Project.
If there is no project for that user, then the View doesn't fire, so you create the menu in Empty Text area. So one menu could be in Global:custom text, and the other in Empty Text.
Similar arguments can be used for many user fields, so play around with them. If you give me more specifics, I might be able to send you more explanation, but really, that should be enough for you to create it.
Joel
Hey Joel, thank you so much! I think i could do it if i would be able to load the currently logged in user in the "Show if the following PHP code returns TRUE" box of the menu block. Can i do that? How?
Alternatively, could you elaborate a bit on your last suggestion please?
Best,
Toon
If it were me, I'd use Views and detect the User based on role and probably use Custom Field module for PHP and do all sorts of tests in there. Since it's a block, though, arguments aren't passed, so you could do a Default argument from PHP and do all sorts of fun PHP code in there, so you wouldn't need an additional module.
Or you could assign a role using a Rule, or have the User based on an argument (again, default argument, Current Logged in User), and use Empty Text to show a different menu based on the existence of that project.
Actually, I kinda like that last idea...
Joel
You could make two blocks, put them in the same place and assign visibility settings based on role. There are many options, though.
Joel
Hello all,
Let's i want to display or not display a menu item depending on some property of the logged in user. E.g. when my user has selected a project (i.e. a reference to the project can be found through the user) i want to display a menu item "my project", if not i want to display a different menu item "available projects". How do i do this? Context? Rules? Menu hooks?
Any ideas?
Best,
Toon
[ Drupal support list | http://lists.drupal.org/ ]
In relationships for Flags, you can have it 'Marked by current user'. Then in Filters you can use that relationship for 'Flag: marked XXX'.
If they haven't marked it, it won't show.
Hope that helps.
Joel
Actually, to make it a bit more complex: there is no user reference field. The project is flagged by a certain user. This is used in the view "my_projects" as a relationship "Flags: student_selected by current user". Is there a way to still do what you described below? The only arguments that seem to be available to add are "Flags: Content ID" and "Flags: Flagged time". Or do i somehow have to create the user reference when flagging (through Rules)?
Thank you so much for your help already!
Best,
Toon On Tue, Jun 7, 2011 at 8:59 PM, Joel Willers joel.willers@sigler.com wrote: For your PHP suggestion, you would use global $user and detect the user role, but you wouldn't be able to easily use this for detecting if they have a project.
For my suggestion, you can use the content type Project (I don't know your configuration, so I'm making some general assumptions), and let's say it has a user reference called field_project_user. You would set that as an argument, and in the section for what to do if there is no argument, you set a default argument as logged in user. Then you set a filter for node:type = Project.
If there is no project for that user, then the View doesn't fire, so you create the menu in Empty Text area. So one menu could be in Global:custom text, and the other in Empty Text.
Similar arguments can be used for many user fields, so play around with them. If you give me more specifics, I might be able to send you more explanation, but really, that should be enough for you to create it.
Joel
Hey Joel, thank you so much! I think i could do it if i would be able to load the currently logged in user in the "Show if the following PHP code returns TRUE" box of the menu block. Can i do that? How?
Alternatively, could you elaborate a bit on your last suggestion please?
Best,
Toon
If it were me, I'd use Views and detect the User based on role and probably use Custom Field module for PHP and do all sorts of tests in there. Since it's a block, though, arguments aren't passed, so you could do a Default argument from PHP and do all sorts of fun PHP code in there, so you wouldn't need an additional module.
Or you could assign a role using a Rule, or have the User based on an argument (again, default argument, Current Logged in User), and use Empty Text to show a different menu based on the existence of that project.
Actually, I kinda like that last idea...
Joel
You could make two blocks, put them in the same place and assign visibility settings based on role. There are many options, though.
Joel
Hello all,
Let's i want to display or not display a menu item depending on some property of the logged in user. E.g. when my user has selected a project (i.e. a reference to the project can be found through the user) i want to display a menu item "my project", if not i want to display a different menu item "available projects". How do i do this? Context? Rules? Menu hooks?
Any ideas?
Best,
Toon -- [ Drupal support list | http://lists.drupal.org/ ]
Joel, thanks for all the help. My view already works fine. I get an empty result if there was no project flagged bu the user, but the corresponding menu item is still displayed. I think i'm missing something. I don't see what you mean by:
"If there is no project for that user, then the View doesn't fire, so you create the menu in Empty Text area. So one menu could be in Global:custom text, and the other in Empty Text."
Thanks again!
Toon
On Tue, Jun 7, 2011 at 10:12 PM, Joel Willers joel.willers@sigler.comwrote:
In relationships for Flags, you can have it 'Marked by current user'. Then in Filters you can use that relationship for 'Flag: marked XXX'.
If they haven't marked it, it won't show.
Hope that helps.
Joel
Actually, to make it a bit more complex: there is no user reference field. The project is flagged by a certain user. This is used in the view "my_projects" as a relationship "Flags: student_selected by current user". Is there a way to still do what you described below? The only arguments that seem to be available to add are "Flags: Content ID" and "Flags: Flagged time". Or do i somehow have to create the user reference when flagging (through Rules)?
Thank you so much for your help already!
Best,
Toon On Tue, Jun 7, 2011 at 8:59 PM, Joel Willers joel.willers@sigler.com wrote: For your PHP suggestion, you would use global $user and detect the user role, but you wouldn't be able to easily use this for detecting if they have a project.
For my suggestion, you can use the content type Project (I don't know your configuration, so I'm making some general assumptions), and let's say it has a user reference called field_project_user. You would set that as an argument, and in the section for what to do if there is no argument, you set a default argument as logged in user. Then you set a filter for node:type = Project.
If there is no project for that user, then the View doesn't fire, so you create the menu in Empty Text area. So one menu could be in Global:custom text, and the other in Empty Text.
Similar arguments can be used for many user fields, so play around with them. If you give me more specifics, I might be able to send you more explanation, but really, that should be enough for you to create it.
Joel
Hey Joel, thank you so much! I think i could do it if i would be able to load the currently logged in user in the "Show if the following PHP code returns TRUE" box of the menu block. Can i do that? How?
Alternatively, could you elaborate a bit on your last suggestion please?
Best,
Toon
If it were me, I'd use Views and detect the User based on role and probably use Custom Field module for PHP and do all sorts of tests in there. Since it's a block, though, arguments aren't passed, so you could do a Default argument from PHP and do all sorts of fun PHP code in there, so you wouldn't need an additional module.
Or you could assign a role using a Rule, or have the User based on an argument (again, default argument, Current Logged in User), and use Empty Text to show a different menu based on the existence of that project.
Actually, I kinda like that last idea...
Joel
You could make two blocks, put them in the same place and assign visibility settings based on role. There are many options, though.
Joel
Hello all,
Let's i want to display or not display a menu item depending on some property of the logged in user. E.g. when my user has selected a project (i.e. a reference to the project can be found through the user) i want to display a menu item "my project", if not i want to display a different menu item "available projects". How do i do this? Context? Rules? Menu hooks?
Any ideas?
Best,
Toon
[ Drupal support list | http://lists.drupal.org/ ]
-- [ Drupal support list | http://lists.drupal.org/ ]
I'm suggesting that the menu is created by the view that I'm discussing. You make it a 'block' view, and have the result be the menu. The empty text is the alternate menu.
So if the menu was <ul><li>Item 1</li><li>Item 2</li><li class="project">Item 3</li></ul>, then have the only field be a Global custom text as the above. Then the empty text should be <ul><li>Item 1</li><li>Item 2</li></ul>
Then go to Blocks and find the view, and use this as the menu.
Joel
Joel, thanks for all the help. My view already works fine. I get an empty result if there was no project flagged bu the user, but the corresponding menu item is still displayed. I think i'm missing something. I don't see what you mean by:
"If there is no project for that user, then the View doesn't fire, so you create the menu in Empty Text area. So one menu could be in Global:custom text, and the other in Empty Text."
Thanks again!
Toon
Hey Joel,
I tried your way but using the view as a context (the context would display or not display a menu block). No luck so far ( i can't seem to get context working properly). Going to let that method rest for a while. Thank you so much for all the help!
Best,
Toon
On Tue, Jun 7, 2011 at 10:57 PM, Joel Willers joel.willers@sigler.comwrote:
I'm suggesting that the menu is created by the view that I'm discussing. You make it a 'block' view, and have the result be the menu. The empty text is the alternate menu.
So if the menu was <ul><li>Item 1</li><li>Item 2</li><li class="project">Item 3</li></ul>, then have the only field be a Global custom text as the above. Then the empty text should be <ul><li>Item 1</li><li>Item 2</li></ul>
Then go to Blocks and find the view, and use this as the menu.
Joel
Joel, thanks for all the help. My view already works fine. I get an empty result if there was no project flagged bu the user, but the corresponding menu item is still displayed. I think i'm missing something. I don't see what you mean by:
"If there is no project for that user, then the View doesn't fire, so you create the menu in Empty Text area. So one menu could be in Global:custom text, and the other in Empty Text."
Thanks again!
Toon
[ Drupal support list | http://lists.drupal.org/ ]
Gee, I'd go low tech and use a custom "access callback" function. "My project" would, for example use the TRUE return, and "Available projects" would negate the return value. Try to keep the logic simple because it may be invoked as often as every page request. If it is more complex, you could add a flag to $user->data in the project assignment code. Nancy
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
From: toon severijns
Let's i want to display or not display a menu item depending on some property of the logged in user. E.g. when my user has selected a project (i.e. a reference to the project can be found through the user) i want to display a menu item "my project", if not i want to display a different menu item "available projects". How do i do this? Context? Rules? Menu hooks?
Thanks Nancy,
I'll have a look at that.
Best,
Toon
On Tue, Jun 7, 2011 at 10:46 PM, Ms. Nancy Wichmann nan_wich@bellsouth.netwrote:
Gee, I'd go low tech and use a custom "access callback" function. "My project" would, for example use the TRUE return, and "Available projects" would negate the return value. Try to keep the logic simple because it may be invoked as often as every page request. If it is more complex, you could add a flag to $user->data in the project assignment code.
*Nancy*
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
*From:* toon severijns
Let's i want to display or not display a menu item depending on some property of the logged in user. E.g. when my user has selected a project (i.e. a reference to the project can be found through the user) i want to display a menu item "my project", if not i want to display a different menu item "available projects". How do i do this? Context? Rules? Menu hooks?
-- [ Drupal support list | http://lists.drupal.org/ ]