By default, oro platform show all actions which get added to your data gird . If you need to hide or show some options depending on the data of the entry, you can manage by adding action_configuration which using a service that decides whether or not an action is visible for an entry:
</p> <p>datagrids: ibnab-acbundle-orders-grid: # … code properties: id: ~ enable_link: type: url route: ibnab_customer_checkout_status params: [ id ] disable_link: type: url route: ibnab_customer_checkout_status params: [ id ] actions: enable: type: ajax label: ibnab.acbundle.frontend.enable acl_resource: oro_order_frontend_view icon: check link: enable_link disable: type: ajax label: ibnab.acbundle.frontend.disable acl_resource: oro_order_frontend_view icon: close link: disable_link action_configuration: ['@ibnab_app_order.action.visibility_provider', getActionsVisibility]
@ibnab_app_order.action.visibility_provider is a public service , the function getActionsVisibility contain your statement responsible to show or hide some actions . Full code of the class :
<?php namespace Ibnab\Bundle\ReplenishmentOrderBundle\Datagrid; use Oro\Bundle\DataGridBundle\Datasource\ResultRecordInterface; class ActionsVisibilityProvider { /** * @param ResultRecordInterface $record * @param array $actions * @return array */ { $visibility = []; foreach ($actions as $action) { $visibility[$action] = true; } $visibility['enable'] = $record->getValue('status') == 0 ? true : false; } $visibility['disable'] = $record->getValue('status') == 1 ? true : false; } return $visibility; } }
Firstly we have started by foreach which affect true to all actions stocked on $visibility table :
foreach ($actions as $action) { $visibility[$action] = true; }
After that we test if some actions has exist like - enable Or disable - and related to value of status field of current line of datagrid we show or hide those actions:
$visibility['enable'] = $record->getValue('status') == 0 ? true : false; } $visibility['disable'] = $record->getValue('status') == 1 ? true : false; }
And finally we return our table by return $visibility .
Comments