What is the best way to add a subpanel(?) for module related via flex relate?

I have a custom module with a Flex Relate and want to display that data on the record view of the Account, Contact, etc..

I am thinking either a custom subpanel, or an e-mail-address-like display within the module itself.

Any suggestions on an approach? Has anyone else done this?

thanks,

FrancescaS

Parents
  • In case someone else comes across this.

    Dooley provided the solution to the custom subpanel here:

    Shane Dowling – SugarCRM 7 - Custom subpanels 

    I set the getRelatedModuleName() to return the name of the custom module with the flex-relate

    and changed the getCustomJoin to filter by the parent type and parent id on the custom module's table

        protected function getCustomJoin($params = array())
        {
            $bean_id = $this->db->quoted($this->focus->id);
            $bean_module = $this->db->quoted($this->focus->module_dir);
            $sql = " INNER JOIN(";
            $sql .= "SELECT id FROM <custom_module_table_name>  where parent_id={$bean_id} and parent_type = {$bean_module}";
            $sql .= ") l_results  ON l_results.id = <custom_module_table_name>.id";
            return $sql;
        }

    I deactivated the link-action on the panel-top using the css_class disabled on subpanel, where <my_module> is the one with the flex relate on it.

    <?php
    $viewdefs['<my_module>']['base']['view']['panel-top'] = array(
      'buttons' => array(
        array(
          'type' => 'button',
          'css_class' => 'btn-invisible',
          'icon' => 'fa-chevron-up',
          'tooltip' => 'LBL_TOGGLE_VISIBILITY',
        ),
        array(
          'type' => 'actiondropdown',
          'name' => 'panel_dropdown',
          'css_class' => 'pull-right',
          'buttons' => array(
            array(
              'type' => 'sticky-rowaction',
              'icon' => 'fa-plus',
              'name' => 'create_button',
              'label' => ' ',
              'acl_action' => 'create',
              'tooltip' => 'LBL_CREATE_BUTTON_LABEL',
            ),
            array(
              'type' => 'link-action',
              'name' => 'select_button',
              'label' => 'LBL_ASSOC_RELATED_RECORD',
              'css_class'=>'disabled'
            ),
          ),
        ),
      ),
    );
    ?>

    And removed access to the unlink rowaction on the subpanel-list, again using the css to disable it.

        'rowactions' => array(
            'actions' => array(
                array(
                    'type' => 'rowaction',
                    'css_class' => 'btn',
                    'tooltip' => 'LBL_PREVIEW',
                    'event' => 'list:preview:fire',
                    'icon' => 'fa-eye',
                    'acl_action' => 'view',
                    'allow_bwc' => false,
                ),
                array(
                    'type' => 'rowaction',
                    'name' => 'edit_button',
                    'icon' => 'fa-pencil',
                    'label' => 'LBL_EDIT_BUTTON',
                    'event' => 'list:editrow:fire',
                    'acl_action' => 'edit',
                    'allow_bwc' => true,
                ),
                array(
                    'type' => 'unlink-action',
                    'icon' => 'fa-chain-broken',
                    'label' => 'LBL_UNLINK_BUTTON',
                     'css_class'  => 'disabled',
                ),
            ),
        ),

    Last but not least, I modified the create on the module with the flex-relate to allow for record creation from subpanel: 

    ({
      extendsFrom: 'CreateView',
      initialize: function(options){
        this._super('initialize', [options]);
        //if creating from subpanel get the parent and set the flex relate
        var parentMod = this.context.parent || null;
        if(!_.isEmpty(parentMod)){
          var parent_module = parentMod.get('module'),
              parent_id = parentMod.get('modelId');
           //there is not a true relationship between this module and the parent
           //the parent is a flex relate field.
           //empty link information brought over by the non-db relationship we created for the subpanel
          this.model.link  ={};
           //set the parent id and parent type
          this.model.set('parent_id', parent_id);
          this.model.set('parent_type', parent_module);
        }
      }
    })

    HTH

    FrancescaS

  • The response above, though it worked in 7.x is far more complicated than necessary.

    For a flex relate, you can leverage an existing Link file: data/Link/FlexRelateChildrenLink.php

    Which reduces the solution described above to a simple vardef addition:

    <?php
    //fields and relationships for WolfTag subpanel
    $dictionary["Account"]["fields"]["wolftag_details"] = array(
                'name' => 'wolftag_details',
                'type' => 'link',
                'link_file' => 'data/Link/FlexRelateChildrenLink.php',
                'link_class' => 'FlexRelateChildrenLink',
                'relationship' => 'account_wolftags_parent',
                'source' => 'non-db',
                'vname' => 'LBL_WOLFTAG_DETAILS',
    );
    $dictionary["Account"]["relationships"]['account_wolftags_parent'] = array(
                'lhs_module' => 'Accounts',
                'lhs_table' => 'accounts',
                'lhs_key' => 'id',
                'rhs_module' => 'wolf_WolfTags',
                'rhs_table' => 'wolf_wolftags',
                'rhs_key' => 'parent_id',
                'relationship_type' => 'one-to-many',
                'relationship_role_column' => 'parent_type',
                'relationship_role_column_value' => 'Accounts',
    );
    ?>

    Also, note that the prior solution made use of joinRaw which is deprecated as of 7.7 and will be removed in 7.9

    Then simply add the subpanel to your module via the Extensions framework:

    custom/Extension/modules/Accounts/Ext/clients/base/layouts/subpanels/<your_file_name>.php

    $viewdefs['Accounts']['base']['layout']['subpanels']['components'][] = array (
      'layout' => 'subpanel',
      'label' => 'LBL_WOLFTAG_DETAILS',
      'context' =>
      array (
        'link' => 'wolftag_details',
      ),
    );

    Francesca

  • Hi Francesca,

    I have applied the same solution for Sugar8 - it works fine, and updates are:

     - you do not need this custom link class anymore

     - vardefs even smaller now: no need for lines anymore

    'link_file' => 'data/Link/FlexRelateChildrenLink.php',
    'link_class' => 'FlexRelateChildrenLink',

    I also made all fields readOnly.

    But, I have got one issue: for some fields on a subpanel there is a value = 'no data', which appears on a record after you click 'Preview' row action for it. Looks like relationship loaded not in full - there is a value for Name field, but Date Created and Parent module has this 'no data' value. The issue appeared after I have disabled edit/link/create/unlink buttons on subpanel , like you did with css.

    I did copy original *.php files (did not copy .js and .hbr) from clients/base/views folder into custom/modules/custom_module/clients/base/views for

    panel-top/panel-top.php

    subpanel-list/subpanel-list.php

    Do I have to copy all files? or do it another way somehow?

    Regards,

    Dmitrii

  • After some investigations found that this is a views/subpanel-list/subpanel-list.php file that makes a crap. As soon as you copy it to custom module folder - Parent_name fields becomes visible on a subpanel and has a value 'no data'. Date created and some other fields also have a value of 'no data'. I have removed this file for current implementation now, until solution is found.

Reply
  • After some investigations found that this is a views/subpanel-list/subpanel-list.php file that makes a crap. As soon as you copy it to custom module folder - Parent_name fields becomes visible on a subpanel and has a value 'no data'. Date created and some other fields also have a value of 'no data'. I have removed this file for current implementation now, until solution is found.

Children
No Data