Hide/disable the "Field Name Placement" field in Sugar 10

In Sugar 10, there's a new user preference to control the field name placement. There is now an option to have field names shown next to the field (default) or above the field (as in previous versions). This field shows on the advanced tab, only when editing a user.

I'd like to disable the option for our users to change this value. I've got the back end working, but ideally I'd like to disable this field on the front end. It's complicated by the fact that 1) this is a bwc module and 2) this preference isn't actually a part of the user record.

Does anyone have any ideas or experience with this? 

  • In case anyone else wonders about this, I actually found a solution. I was able to modify editviewdefs.php for the Users module. I added an "includes" section which loaded a custom javascript file when the used edit action was called. Then I used jQuery to disable the field. 

    Sample from editviewdefs.php:

    $viewdefs['Users']['EditView'] = array(
        'templateMeta' => array('maxColumns' => '2',
                                'widths' => array(
                                    array('label' => '10', 'field' => '30'),
                                    array('label' => '10', 'field' => '30')
                                ),
                                'form' => array(
                                    'headerTpl'=>'modules/Users/tpls/EditViewHeader.tpl',
                                    'footerTpl'=>'modules/Users/tpls/EditViewFooter.tpl',
                                ),
                                'includes' => array(
                                     array(
                                          'file' => 'custom/modules/Users/js/labelPlacement.js'
                                     )
                                )
                          ),

    Javascript file labelPlacement.js:

    $(function() {
         $("[name='field_name_placement']").prop('disabled', true);
    });
  • Another way to implement without the javascript override is to make the label option the only available option.

    This file is in custom/modules/Users/UserViewHelper.php and you just need to remove the option for placement on side. 

    <?php


    class CustomUserViewHelper extends UserViewHelper
    {

        public function __construct(Sugar_Smarty &$smarty, SugarBean &$bean, $viewType = 'EditView')
        {
            parent::__construct($smarty, $bean, $viewType);
        }

        /**
         * Override
         */
        protected function setupAdvancedTabNavSettings()
        {
            parent::setupAdvancedTabNavSettings(); // TODO: Change the autogenerated stub

            $field_name_placement = $this->bean->getPreference('field_name_placement') ?? 'field_on_side';
            $field_name_placement_options = [
    //            'field_on_side' => translate('LBL_BESIDE_FIELD_VALUE', 'Users'),
                'field_on_top' => translate('LBL_ABOVE_FIELD_VALUE', 'Users'),
            ];
            $this->ss->assign(
                'FIELD_NAME_PLACEMENT',
                get_select_options_with_id($field_name_placement_options, $field_name_placement)
            );
        }
    }
  • Thanks Shad. I like the simplicity of that approach. I'm assuming you just have to create this file in the /custom/modules/Users directory? I didn't find a version of it in that directory by default. But after dropping in that file, it worked great.

  • Sorry I put it in the comment above but it was sort of hidden. Path is below and the naming of the file and class is important due to how the override is looked for. Glad it helped.

    custom/modules/Users/UserViewHelper.php