0

I want to override this file :

vendor/magento/module-catalog/Ui/DataProvider/Product/Form/NewCategoryDataProvider.php

How can i do this?
just want to change 'include_in_menu' => 1, to 0 .

registration.php:

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Customwork_Menuvalue',
__DIR__
);

module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Customwork_Menuvalue" setup_version="1.0.0">
    </module>
</config>

di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Catalog\Ui\DataProvider\Product\Form\NewCategoryDataProvider" type="Customwork\Menuvalue\Ui\NewCategoryDataProvider" />
</config>

NewCategoryDataProvider.php

<?php
namespace Customwork\Menuvalue\Ui;

use Magento\Ui\DataProvider\AbstractDataProvider;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Framework\UrlInterface;

/**
 * DataProvider for new category form
 *
 * @api
 * @since 101.0.0
 */
class NewCategoryDataProvider extends \Magento\Catalog\Ui\DataProvider\Product\Form\NewCategoryDataProvider
{
    public function getData()
    {
        $this->data = array_replace_recursive(
            $this->data,
            [
                'config' => [
                    'data' => [
                        'is_active' => 1,
                        'include_in_menu' => 0,
                        'return_session_messages_only' => 1,
                        'use_config' => ['available_sort_by', 'default_sort_by']
                    ]
                ]
            ]
        );

        return $this->data;
    }
}
  • Did you tried creating its preference – Narendra Vyas Mar 25 at 13:46
  • it give me an error : Fatal error: Class 'Customwork\Menuvalue\Ui\Magento\Catalog\Ui\DataProvider\Product\Form\NewCategoryDataProvider' not found in /var/www/html/olympic-supply-company/app/code/Customwork/Menuvalue/Ui/NewCategoryDataProvider.php on line 18 – Hafiz Arslan Mar 25 at 14:33
  • check my updated question – Hafiz Arslan Mar 25 at 14:42
  • is your issue resolved ? – Amit Bera Mar 26 at 8:03
  • yeah , this working perfect – Hafiz Arslan Mar 27 at 7:11

Your Answer

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

Browse other questions tagged or ask your own question.