0

Is there any way to disable all input fields on the product admin for a specific admin role in a custom module.

The specific admin role should only view the content but not have the access to edit/update them.

3
  • There is no way to archive your requirement, you need to do customization for it. Commented Jul 14, 2023 at 9:28
  • yes but how ? any idea ?
    – Cv Gandhi
    Commented Jul 14, 2023 at 9:29
  • 1
    Find it by your self, and have us to help you on review your code.
    – HoangHieu
    Commented Jul 14, 2023 at 13:57

1 Answer 1

1

try it like this

[Vendor]/[Module]/view/adminhtml/layout/catalog_product_edit.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="before.body.end">
          <block class="Magento\Framework\View\Element\Template" template="[Vendor]_[Module]::hideattribute.phtml" name="after"/> 
        </referenceContainer>
    </body>
</page>

[Vendor]/[Module]/view/adminhtml/templates/disableattribute.phtml

<?php
    $role_id = 3; //user's role id for example I have used "3"
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $adminSession = $objectManager->get('Magento\Backend\Model\Auth\Session');
    $current_adminuser =    $adminSession->getUser()->getRole()->getRoleId();
?>
<?php if($role_id == $current_adminuser): ?>
    <style>
[data-index = status],[data-index = attribute_set_id],[data-index = attribute_set_id],[data-index = name],[data-index = sku],[data-index = tax_class_id],[data-index = container_weight],[data-index = container_category_ids],[data-index = visibility],[data-index = container_news_from_date],[data-index = country_of_manufacture],[data-index = activity] {
        display: none;
    }
    </style>
<?php endif; ?>

just update [data-index = yourattributeid] this is just an example do not use objectmanager and create a block and call them using factory method

1
  • happy to help......
    – Pramod
    Commented Jul 18, 2023 at 1:39

Your Answer

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

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