Address FieldSet - How to redefine the field organzation for the pre-set the address block

Hello,

Currently, Sugar provides a default layout to display an address field (for instance the billing address of an account, the primary address of a contact etc.).

THis template is not really accurate according to our locale settings.

Is there a proper and upgraed safe way to redefine this template, instead of having to modify the record.php view each time this address field is included ?

Best regards,

Fred

Parents
  • The way Fieldset works is a bit complicated? - it picks the template from the record view itself and reuses it somehow - and there is no easy way to modify the core files like record.php.

    So we did a work around: Use the extension framework to force-update the fieldset layout, like a hack.

    Eg: create a file where you would usually define your view, say: custom/Extension/modules/Accounts/Ext/clients/base/views/record/address_fieldset.php


    <?php
    
    foreach ($viewdefs['Accounts']['base']['view']['record']['panels'] as &$panel) {
        foreach ($panel['fields'] as &$field) {
            if (is_array($field) && $field['name'] == 'billing_address') {
                $field = [
                    'name' => 'billing_address',
                    'type' => 'fieldset',
                    'css_class' => 'address',
                    'label' => 'LBL_BILLING_ADDRESS',
                    'fields' => [
                        [
                            'name' => 'billing_address_country',
                            'css_class' => 'address_country',
                            'placeholder' => 'LBL_BILLING_ADDRESS_COUNTRY',
                        ],
                        [
                            'name' => 'billing_address_street',
                            'css_class' => 'address_street',
                            'placeholder' => 'LBL_BILLING_ADDRESS_STREET',
                        ],
                        [
                            'name' => 'billing_address_city',
                            'css_class' => 'address_city',
                            'placeholder' => 'LBL_BILLING_ADDRESS_CITY',
                        ],
                        [
                            'name' => 'state_list_c',
                            'css_class' => 'address_state',
                            'placeholder' => 'LBL_BILLING_ADDRESS_STATE',
                        ],
                    ],
                ];
            }
        }
    }
    

    What we're trying to do here is - when the view is built, we'll force update the fieldset fields with the ones we want. The record.php might still use the default template, but this will override it every time.

    This is a weird way to make it work, but it works!

Reply
  • The way Fieldset works is a bit complicated? - it picks the template from the record view itself and reuses it somehow - and there is no easy way to modify the core files like record.php.

    So we did a work around: Use the extension framework to force-update the fieldset layout, like a hack.

    Eg: create a file where you would usually define your view, say: custom/Extension/modules/Accounts/Ext/clients/base/views/record/address_fieldset.php


    <?php
    
    foreach ($viewdefs['Accounts']['base']['view']['record']['panels'] as &$panel) {
        foreach ($panel['fields'] as &$field) {
            if (is_array($field) && $field['name'] == 'billing_address') {
                $field = [
                    'name' => 'billing_address',
                    'type' => 'fieldset',
                    'css_class' => 'address',
                    'label' => 'LBL_BILLING_ADDRESS',
                    'fields' => [
                        [
                            'name' => 'billing_address_country',
                            'css_class' => 'address_country',
                            'placeholder' => 'LBL_BILLING_ADDRESS_COUNTRY',
                        ],
                        [
                            'name' => 'billing_address_street',
                            'css_class' => 'address_street',
                            'placeholder' => 'LBL_BILLING_ADDRESS_STREET',
                        ],
                        [
                            'name' => 'billing_address_city',
                            'css_class' => 'address_city',
                            'placeholder' => 'LBL_BILLING_ADDRESS_CITY',
                        ],
                        [
                            'name' => 'state_list_c',
                            'css_class' => 'address_state',
                            'placeholder' => 'LBL_BILLING_ADDRESS_STATE',
                        ],
                    ],
                ];
            }
        }
    }
    

    What we're trying to do here is - when the view is built, we'll force update the fieldset fields with the ones we want. The record.php might still use the default template, but this will override it every time.

    This is a weird way to make it work, but it works!

Children