SugarCRM: Upgrade Safe Way to Extend Views
Extending Views is fun and easy to do, but did you know there is a right way and a wrong way to extend module views. Well I shouldn’t say wrong as it still works but it’s non-upgrade safe, and from my experience it will cause you headaches after you do an upgrade and something is not working correctly. Click Read More to see what I’m talking about.
Lets say you have this file for in your custom/modules/Contacts/views/view.detail.php
While it will work, if SugarCRM ever updated the base file in modules/Contacts/views/view.detail.php you wont have the new functionality that was put into place. If we write the view like this
Not only are we upgrade safe, it’s much cleaner in the long run as you don’t have to copy any form the base class over.
No View Defined In Module
What if the module does have a view.detail.php or a view.edit.php in the modules//views folder. Well don’t worry, it’s still very easy to do. Just override the base view class. But after an upgrade make sure that there wasn’t one added if it’s a OOB module.
I can only hope this helps people write better customizations.
Cheers!
Neat!
I did not know that there was the reserved keyword ‘Custom’ that could be used in front of the normal view class name. Good to know!
It would be nice to have the same behaviour on beans, so that we can extend those if required
Cheers
Thanks for the great tips!
Just double checked the view factory, it seems that we have to use the word “Custom” for custom class.
Great stuff! Just what I was working on, except I’m extending the view.list.php of an Activities module. If I try to put it in custom/modules/Activities/views and extend the class using CustomActivitiesViewList extends ActivitiesViewList, it does not seem to work. By the way all this on an ancient 5.2.0e version of sugar.
I do believe that is is only on 5.5+ version of SugarCRM.
Thank you so much. After much searching, you solved my problem. This is the first place I’ve seen that you have to use the *magic* “Custom” prefix for your class name. Not sure what happens when other modules try to extend the same view.