2

I added a new column to product grid on back-office Magento, but I want to display it where the role is " admin " and hide it if not.

I add the column using this code :

<column name="user_id">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="filter" xsi:type="string">text</item>
            <item name="editor" xsi:type="array">
            <item name="editorType" xsi:type="string">text</item>
            <item name="validation" xsi:type="array">
                <item name="required-entry" xsi:type="boolean">true</item>
            </item>
        </item>
        <item name="label" xsi:type="string" translate="true">User</item>
        </item>
    </argument>
</column>
  • Did you have a created custom module for adding a new column? – Kamlesh Solanki Apr 30 '19 at 8:41
  • @KamleshSolanki yes sir – sayou Apr 30 '19 at 8:45
  • Then you have to create acl.xml for your module and given custom permission for a particulre user from the backend. – Kamlesh Solanki Apr 30 '19 at 8:48
  • @KamleshSolanki I have an ACL, but I added a new column to product grid, so, I need to add permission just to it, and hide it when the role is not Admin – sayou Apr 30 '19 at 8:49
  • But it is not possible to given particular column permission in Magento. But I am not sure it is possible or not – Kamlesh Solanki Apr 30 '19 at 8:52
3

To help more people to fix this problem I will share the solution :

first, you need to add this code to your ui_componenet XML file

<item name="componentDisabled" xsi:type="boolean">true</item>

after you will create a file on NAMESPACE/MODULE/Ui/Listing/Columns/yourfile.php with this code :

public function prepare()
    {
        parent::prepare();
        if (YOUR_CONDITION) { 
            $this->_data['config']['componentDisabled'] = false;
        }
    }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.