#2463 - Run-time switching between group views of custom modules
Hi, I have a user with multiple groups and for each group, I have different views setup for my custom modules. I need to switch between edit views on page load using specific criteria. Can I accomplish this requirement?
8 years ago
Yes, but it will take a little work. Within include/MVC/Views are all the major views. If you open view.edit.php look inside the preDisplay() function. This is how it determines which layout to show the user. The best approach for your custom module is to have a view.edit.php and override the preDisplay() to add your logic.
Hope that helps!
8 years ago
Thanks for quick reply. I was thinking of doing it with some other way as I don't want to edit all views for all modules (a lot of time and work). Is it possible that I can change the default group to be considered for opening views? I actually have a scenario where if the user selects a group, for a specific time (I'm using core PHP sessions - $_SESSION to handle this), it starts to show all views related to that department only. Like, if a user selects group A after login, he can only view all views of all custom modules related to group A. If he selects group B at a later time, he can only see all views related to group B for all custom modules.
8 years ago
It looks like you can just set the group ID in $_SESSION['groupLayout'] and it should work.
8 years ago
Thanks for the tip. Just a little thing remaining. Its working for detail view. But its not working for sub panels. Any hint regarding that?
8 years ago
Custom group subpanels aren't supported by SecuritySuite. Anything relating to that will be something in the /include/SubPanel and /include/ListView directories.
8 years ago
Sorry for the mistake. I wanted to refer to QuickCreate view.
8 years ago
I'll look into that. Quick peek tells me that the SecuritySuite code required to make that work isn't there. What version of SugarCRM or SuiteCRM are you on?
8 years ago
I'm using SugarCRM CE Version 6.5.24 (Build 509)
8 years ago
And please clarify one thing. Does this $_SESSION['groupLayout'] renews its value on every page load? If yes, where I can put the code to make it work until I change it manually?
8 years ago
Every page load. It just needs to be set before the view loads. It will take some playing around to find the right place for you based on however you handle that logic. It may need to be a hard coded change or a logic hook: http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.6/Logic_Hooks/Application_Hooks/
8 years ago
Once it is set though it won't be unset. You will still want to likely set every page load to be safe.
8 years ago
Basically I'm hitting a custom entry point and set $_SESSION['groupLayout'] to the value I pass in entry point. . After which the first page load works totally fine. But when I refresh it, or use sub-panel quick create, my stored value doesn't seem to work anymore.
8 years ago
Just found the issue. I just needed to remove unset($_SESSION['groupLayout']); **under \include\TemplateHandler\TemplateHandler.php**
Do guide me if you can help regarding one last issue. I now only face this value being destroyed whenever I open any list view.
8 years ago
I'd advise just commenting out that unset for your needs or always set it before every view change. Not much else that can be done from what I can see.
8 years ago
Thanks for your help. Setting variables in TemplateHandler constructor does the job for me. Thanks again for your help.