0

I am looking into if it is indeed possible to disable the ability for a user to drag / move and drop categories in the Magento2 admin panel.

Any guidance or suggestions on how to accomplish this on per user basis or just a global disable for all users would be greatly appreciated.

1 Answer 1

0

You can do it via overwriting core module code via your custom module.

Create the di.xml in following Path {Vendor_Module}/etc/adminhtml/di.xml

Add the below code in it.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Catalog\Block\Adminhtml\Category\Tree" 
    type="Grazitti\Minicart\Block\Adminhtml\Category\Tree"/>
</config>

Then Override the Tree.php file {Vendor_Module}\Block\Adminhtml\Category\Tree.php

Then in your find the below function

 protected function _getNodeJson($node, $level = 0)

Find below line in this function

$item['allowDrag'] = $allowMove && ($node->getLevel() == 1 && $rootForStores ? false : true);

Replace with

$item['allowDrag'] = $allowMove && ($node->getLevel() == 1 && $rootForStores ? false : false);
1
  • Ah that looks promising and make sense. I will try this out over the coming weekend and provide feedback.
    – Baber
    Nov 23, 2023 at 12:12

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.