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.

  • Hi Artis Plocins 

    I believe this article is useful.

    Good luck!

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hi, thanks but I've seen that page already and it only explains how to add something in viewdefs, not remove an element from it or change a single property of an element like a button type. Is there really no way to do that other than fully overriding the entire record.php file?

  • You may remove elements as well. You just have to walk through all buttons in order to make sure you will remove the correct one. Inside this walkthrough you need to look for a specific button attribute in order to identify the target one.

    We had done that previously without big deal.

    Good luck!

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Can you please check and see why this bit of code does not do anything like I think it should?

    This is the first thing I tried, and I tried again and it still doesn't work.

    In the file custom/Extension/modules/Calls/Ext/clients/base/views/record/record.php

    <?php

    foreach ($viewdefs['Calls']['base']['view']['record']['buttons'] as &$button) {
      if ($button['name'] == 'save_dropdown') {
        foreach ($button['buttons'] as &$btn) {
          if ($btn['name'] == 'save_invite_button') {
            unset($btn);
          }
        }
      }
    }

    After rebuilding and clearing the cache, the button is still there:

    Although this should also work, in theory, but doesn't:

    function remove_button(&$item) {
        if ($item['name'] == 'save_invite_button') {
            unset($item);
        }
    }

    array_walk_recursive($viewdefs['Calls']['base']['view']['record']['buttons'], 'remove_button');
  • Your code must be something like that:

    <?php

    foreach ($viewdefs['Calls']['base']['view']['record']['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']['record']['buttons'][$i]['buttons'][$j]
    );
         
    }
       
    }
     
    }
    }
    André Lopes
    Lampada Global
    Skype: andre.lampada
  • I see, that works. Thank you!

    But when I try to do the same for the create view in file custom/Extension/modules/Calls/Ext/clients/base/views/create/create.php this does not work:

    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]);
          }
        }
      }
    }

    But again, the direct unset() by numbered indexes like I showed above still works, so it is definitely possible. Why is this same method not working in this case?

  • Can you kindly share the content of your custom/modules/Call/clients/base/views/create/create.php?

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • 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
1 2