0

I try to customize product creation form using modifier class

this is my di.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <virtualType name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool">
        <arguments>
            <argument name="modifiers" xsi:type="array">
                <item name="customField" xsi:type="array">
                    <item name="class" xsi:type="string">AddOnSystem\ProductApproval\Ui\DataProvider\Product\Form\Modifier\CustomField</item>
                    <item name="sortOrder" xsi:type="number">20</item>
                </item>
            </argument>
        </arguments>
    </virtualType>
</config>

and this is my modifier class

<?php
namespace AddOnSystem\ProductApproval\Ui\DataProvider\Product\Form\Modifier;

use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Ui\Component\Form;
use Magento\Catalog\Model\Locator\LocatorInterface;
use AddOnSystem\ProductApproval\Helper\Data;

class CustomField extends AbstractModifier
{
    public function __construct(
        Context $context,
        ArrayManager $arrayManager,
        LocatorInterface $locator,
        Data $helper
    ){
        $auth= $context->getAuth();
        $loginUser=$auth->getUser();
        $loginUserRole=$loginUser->getRole();
        $this->role = $loginUserRole;
        $this->arrayManager = $arrayManager;
        $this->locator = $locator;
        $this->helper = $helper;
    }

    public function modifyData(array $data)
    {
        return $data;
    }

    public function modifyMeta(array $meta)
    {
        $disabled = true;
        $role = $this->role;
        $roleList = $this->helper->getGeneralConfig('listrole');

        if(in_array($role['role_id'], $roleList)){
            $disabled = false;
        }

         $switcherConfig = [
            'disabled' => $disabled,
        ];

        $path = $this->arrayManager->findPath('addonsys_product_approval', $meta, null, 'children');
        $meta = $this->arrayManager->merge($path . static::META_CONFIG_PATH, $meta, $switcherConfig);

        return $meta;
    }
}

the problem is when I try to do bin/magento it throws an error

Invalid Document
Element 'item': The type definition is abstract.
Line: 7

Element 'item', attribute 'name': The XPath '@name' of a field of key identity-constraint 'itemName' evaluates to a node-set with more than one member.
Line: 45

Element 'item': Not all fields of key identity-constraint 'itemName' evaluate to a node.
Line: 45

Element 'item', attribute 'name': The XPath '@name' of a field of key identity-constraint 'itemName' evaluates to a node-set with more than one member.
Line: 46

Element 'item': Not all fields of key identity-constraint 'itemName' evaluate to a node.
Line: 46

the problem only exists when I use Magento mode developer, and this code actually works in the system, please help, how to fix this

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.