Results 1 to 6 of 6

Thread: Override class function

  1. #1
    hzara's Avatar
    hzara is offline Member
    Join Date
    Nov 2008
    Posts
    13

    Question Override class function

    Hi all,

    I need to override

    include/SubPanel/SubPanelDefinitions.php ---> class aSubPanel ---> function load_sub_subpanels()

    because since sugar version 5.2 new code has been added to this function (from //call this function for sub-panels that have unions. on until the end of the funciont) that generates display problems with a custom subpanel display a colletion.

    I've tryed almost everything (almost because I haven't found the solution.

    Basically I need an upgrade safe solution que get rid of part of the code in standard function!

    Thanks in advance.
    Herb

  2. #2
    rafael.q.g@hotmail.com's Avatar
    rafael.q.g@hotmail.com is offline Sugar Community Member
    Join Date
    Jun 2011
    Location
    Florianópolis - Brazil
    Posts
    782

    Default Re: Override class function

    To make a safe customization of this method, you could just move your customized file to:
    custom/include/SubPanel/SubPanelDefinitions.php

    This way you can upgrade your sugarcrm system, and your changes will be keeped.
    Rafael Queiroz Gonçalves
    Advanced OMG UML Certified Professional
    Sun Certified Enterprise Architect for the Java Platform
    Sun Certified Programmer for the Java 2 Platform
    IBM Certified Advanced Application Developer - Lotus Notes and Domino
    IBM Certified Application Developer - IBM WebSphere Portlet Factory
    Computer Science Mastering / UFSC - PPGCC

  3. #3
    hzara's Avatar
    hzara is offline Member
    Join Date
    Nov 2008
    Posts
    13

    Default Re: Override class function

    Rafael, thanks for your reply.

    I've tryed what you porpose, but it doesn't work. It can't find the custom file. I even renamed the original file in the original folder, just to see if redirected to the custom directory, and didn't find it.

    Got the following:
    Warning: require_once(include/SubPanel/SubPanelDefinitions.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\axl_614_a\include\SubPanel\SubPane lTilesTabs.php on line 41.

    I've tryed to force the custom file you sugest in the corresponding detailviewdefs.php, view.detail.php, and even the module been file, ... and no luck

    Any other idea?

  4. #4
    PanJun is offline Sugar Community Member
    Join Date
    Nov 2008
    Location
    Shanghai
    Posts
    50

    Cool Re: Override class function

    I have another upgrade safe solution.

    If "custom/include/SubPanel/SubPanelDefinitions.php" works for all subpanels, then my solution will only effect on one module.

    You have to prepare two custom class:
    - CustomSubPanelDefinitions (which extends "include/SubPanel/SubPanelDefinitions.php")
    - CustomSubPanelTiles (which extends "include/SubPanel/SubPanelTiles.php")

    Then, override function _displaySubPanels() in your view.detail.php.
    PHP Code:
        function _displaySubPanels() {
            if (isset(
    $this->bean) && !empty($this->bean->id) && (file_exists('modules/' $this->module '/metadata/subpaneldefs.php') || file_exists('custom/modules/' $this->module '/metadata/subpaneldefs.php') || file_exists('custom/modules/' $this->module '/Ext/Layoutdefs/layoutdefs.ext.php'))) {
                
    $GLOBALS['focus'] = $this->bean;
                require_once (
    'custom/modules/<YOUR MODULE>/views/CustomSubPanelTiles.php');
                
    $subpanel = new CustomSubPanelTiles($this->bean$this->module);
                echo 
    $subpanel->display();
            }
        } 
    CustomSubPanelTiles.php
    PHP Code:
    require_once ('include/SubPanel/SubPanelTiles.php');
    require_once (
    'custom/modules/<YOUR MODULE>/views/CustomSubPanelDefinitions.php');

    class 
    CustomSubPanelTiles extends SubPanelTiles {

        function 
    CustomSubPanelTiles(&$focus$layout_def_key=''$layout_def_override '') {
            
    parent::SubPanelTiles(&$focus$layout_def_key$layout_def_override);
            
    $this->subpanel_definitions = new CustomSubPanelDefinitions($focus$layout_def_key$layout_def_override);
        }


    CustomSubPanelDefinitions.php
    PHP Code:
    require_once('include/SubPanel/SubPanelDefinitions.php');
    class 
    CustomSubPanelDefinitions extends SubPanelDefinitions {

        function 
    CustomSubPanelDefinitions($focus$layout_def_key ''$layout_def_override '') {
            
    parent::SubPanelDefinitions($focus$layout_def_key$layout_def_override);
        }

        function 
    load_subpanel($name$reload false$original_only false) {
            if (!
    is_dir('modules/' $this->layout_defs['subpanel_setup'][strtolower($name)]['module']))
                return 
    false;

            
    // CUSTOM CODE

            
    return new aSubPanel($name$this->layout_defs['subpanel_setup'][strtolower($name)], $this->_focus$reload$original_only);
        }

    You can rebuild your aSubPanel inner class in the CustomSubPanelDefinitions.

    I hope this can help you.

    Pan Jun
    Last edited by PanJun; 2011-09-06 at 05:40 AM.

  5. #5
    hzara's Avatar
    hzara is offline Member
    Join Date
    Nov 2008
    Posts
    13

    Default Re: Override class function

    Pan Jun, Thanks.

    I'll try it and get back ASAP!!!!

    Herb

  6. #6
    emsys is offline Junior Member
    Join Date
    Mar 2009
    Posts
    8

    Default Re: Override class function

    Hi Herb,

    Have you tried Pan Jun's method OR found an alternate solution. I am looking for similar solution where I need to customize SubPanel class (the constructor function)

    Thanks in advance.

    Thanks,

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to override Person template function?
    By ewpeanutty in forum Developer Help
    Replies: 11
    Last Post: 2011-10-07, 02:45 PM
  2. can I override a bean class ?
    By Blake Peterson in forum Developer Help
    Replies: 4
    Last Post: 2011-08-15, 02:48 PM
  3. how to override send_back js function
    By zaska in forum Developer Help
    Replies: 3
    Last Post: 2010-12-14, 10:08 AM
  4. [Help]How to Override SugarBean Function
    By blitz2190 in forum Help
    Replies: 1
    Last Post: 2010-08-26, 08:32 PM
  5. Override Contact class
    By maxime.lambert in forum Help
    Replies: 3
    Last Post: 2009-06-14, 08:56 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •