Extend viewdefs to change a value for a button

I am trying to disable a button in the Save button dropdown in a module's record view.

I would like to do that for just that single button without overriding the entire file, so I thought I would create and extension file for the record view and unset that array element.

Obviously if there are other extensions adding more buttons in this dropdown, I don't want to unset the wrong one, so I tried all kinds of foreach loops with if statements, array_walk_recursive(), array_map() and more foreach loops referencing the original array.

The only actual way I managed to do it is still this:

unset($viewdefs['Calls']['base']['view']['record']['buttons'][1]['buttons'][1]);

And if another button gets added at the top of the dropdown, this should theoretically remove the wrong button!

I cannot find anything in the documentation or examples of how this simple thing should be done besides copying the entire file. I believe that would make this simple change affect any other modules also trying to affect the same view.

Parents Reply Children
  • Hi, as in the post above:

    <?php

    foreach ($viewdefs['Calls']['base']['view']['create']['buttons'] as $i => $button) {
      if ($button['name'] == 'save_dropdown') {
        foreach ($button['buttons'] as $j => $btn) {
          if ($btn['name'] == 'save_invite_button') {
            unset($viewdefs['Calls']['base']['view']['create']['buttons'][$i]['buttons'][$j]);
          }
        }
      }
    }
  • Can you see why the same kind of code for record view doesn't work for create view?

  • Hi Artis Plocins 

    I had asked for the viewdefs for Calls/create, not the extended customization for its.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hi Artis, 

    I think you are really close, just in the create view the the array that controls that dropdown is 

                'name' => 'main_dropdown',

    So for your code:

    custom/Extension/modules/Calls/Ext/clients/base/views/create/create.php

    it should be

    <?php

    foreach ($viewdefs['Calls']['base']['view']['create']['buttons'] as $i => $button) {
      if ($button['name'] == 'main_dropdown') {
        foreach ($button['buttons'] as $j => $btn) {
          if ($btn['name'] == 'save_invite_button') {
            unset($viewdefs['Calls']['base']['view']['create']['buttons'][$i]['buttons'][$j]);
          }
        }
      }

    And then Quick Repair and Rebuild.

    In situations like this, I often use a log line to see what arrives in the code. You can do that anywhere with: 

     $GLOBALS['log']->fatal("artis: ".print_r($array,true));

    Then you can monitor the sugarcrm.log to see if for example an if condition is not fulfilled. 

    ------

    A different way to approach disabling the existing item without overwriting would be just to extend the CreateView. 

    Create a file:

    custom/modules/Meetings/clients/base/views/create/create.js

    With content: 

    ({
                    extendsFrom:'CreateView',
                            initialize:function(options){
                                    this._super('initialize',[options]);
                                    this.on('render', this.disableSaveInviteButton,this);
                                     },
                            disableSaveInviteButton:function(){
                                          var saveInviteButton;
                                          saveInviteButton=this.getField('save_invite_button');
                                          saveInviteButton.setDisabled(true);
                                    },
    })

    Then run a Quick Repair or rebuild the cache and the button will be disabled.

    Let me know if that worked for you. 

    Thanks, 

    Dennis 

  • This was immensely helpful and worked. Thank you very much!