I would like to have a parameter which if selected Yes, the dealers of the webpage aren't able to modify any customer information. If selected No, nothing happens and they can modify anything they desire about the customer.

I have added the parameter in the backend:

enter image description here

The code behind the parameter in: app/code/<vendor>/<module>/etc/adminhtml/system.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        <tab id="tabId" translate="label" sortOrder="0">
    <section id="section_id">


        <group id="customer">                

            <field id="permission_info_dealer" translate="label" type="select" sortOrder="105"
                   showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Allow dealer edit customer data </label>


So as I said I would like depending on the user role, be able to remove or hide this Edit from

Admin-> Customers -> All Customers

when the Yes is selected:

enter image description here

The Edit button with the xml code:

 <action name="edit">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="type" xsi:type="string">edit</item>
                    <item name="label" xsi:type="string" translate="true">Edit</item>
                    <item name="callback" xsi:type="array">
                        <item name="provider" xsi:type="string">customer_listing.customer_listing.customer_columns_editor</item>
                        <item name="target" xsi:type="string">editSelected</item>

And I have this code app/code/<vendor>/<module>/Block/Form/Edit.php:


namespace <vendor>\<module>\Block\Form;

class Edit extends \Magento\Customer\Block\Form\Edit
   const PERMISSION_INFO_DEALER = 'gsp_configuration/customer/permission_info_dealer';

    public function canEditInfoDealer()
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $scopeConfig = $objectManager->create('Magento\Framework\App\Config\ScopeConfigInterface');

        return $scopeConfig->getValue(self::PERMISSION_INFO_DEALER, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

    protected function _prepareForm()
        $role = $this->_getRole();
        $gspRole = $this->gspRoleFactory->create()->load($role->getId(), 'role_id');

        $data['permission_info_dealer'] = $gspRole->getData('permission_info_dealer');

        $form = $this->_formFactory->create(
            ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]

        $fieldset = $form->addFieldset(
            ['legend' => __('GSP: Additional Permissions'), 'collapsable' => true]

        $yesno = $this->yesnoFactory->create()->toOptionArray();

        'select', [
        'name' => 'gsp_permission_info_dealer',
        'label' => __('Allow dealer edit customer data'),
        'title' => __('Allow dealer edit customer data'),
        'values' => $yesno,
        'value' => isset($data['permission_info_dealer']) ? $data['permission_info_dealer'] : 1


        return $this;

    protected function _getRole()
        return $this->_coreRegistry->registry('current_role');


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.