I have created a custom module. In which I want to use data modifier. I have written this code but it gives the following error:
Missing required argument $modifiers of Magento\Ui\DataProvider\Modifier\Pool
My Code is Like di.xml
<virtualType name="Vendor\Module\Ui\DataProvider\Customer\Form\Modifier\Pool" type="Magento\Ui\DataProvider\Modifier\Pool">
<arguments>
<argument name="modifiers" xsi:type="array">
<item name="customer" xsi:type="array">
<item name="class" xsi:type="string">Vendor\Module\Ui\DataProvider\Customer\Form\Modifier\Customer</item>
<item name="sortOrder" xsi:type="number">120</item>
</item>
</argument>
</arguments>
</virtualType>
<type name="Vendor\Module\Ui\DataProvider\Customer\Form\Modifier\CustomerDataProvider">
<arguments>
<argument name="pool" xsi:type="object">Vendor\Module\Ui\DataProvider\Customer\Form\Modifier\Pool</argument>
</arguments>
</type>
<type name="Vendor\ModuleUi\DataProvider\Customer\Form\Modifier\Customer">
<arguments>
<argument name="scopeName" xsi:type="string">customer_form.customer_form</argument>
</arguments>
</type>
CustomerDataProvider.php
namespace Vendor\Module\Ui\DataProvider\Customer\Form;
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory;
use Magento\Ui\DataProvider\AbstractDataProvider;
use Magento\Ui\DataProvider\Modifier\ModifierInterface;
use Magento\Ui\DataProvider\Modifier\PoolInterface;
/**
* DataProvider for product edit form
*/
class CustomerDataProvider extends AbstractDataProvider
{
/**
* @var PoolInterface
*/
private $pool;
/**
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param CollectionFactory $collectionFactory
* @param PoolInterface $pool
* @param array $meta
* @param array $data
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
CollectionFactory $collectionFactory,
PoolInterface $pool,
array $meta = [],
array $data = []
) {
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->collection = $collectionFactory->create();
$this->pool = $pool;
}
/**
* {@inheritdoc}
*/
public function getData()
{
/** @var ModifierInterface $modifier */
foreach ($this->pool->getModifiersInstances() as $modifier) {
$this->data = $modifier->modifyData($this->data);
}
return $this->data;
}
/**
* {@inheritdoc}
*/
public function getMeta()
{
$meta = parent::getMeta();
/** @var ModifierInterface $modifier */
foreach ($this->pool->getModifiersInstances() as $modifier) {
$meta = $modifier->modifyMeta($meta);
}
return $meta;
}
}
modifier file Customer.php
<?php
namespace Vendor\Module\Ui\DataProvider\Customer\Form\Modifier;
use Magento\Ui\DataProvider\Modifier\ModifierInterface;
/**
* Class Prices
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Customer implements ModifierInterface
{
/**
* {@inheritdoc}
*/
public function modifyMeta(array $meta)
{
return $meta;
}
/**
* {@inheritdoc}
*/
public function modifyData(array $data)
{
return $data;
}
}
I can't find where it is missing arguments. Please correct way to add modifiers.
Note - I am adding this modifier for customer edit form