15

A compilation was started.

Interception cache generation... 6/7 [========================>---] 85% 1 min 404.0 MiB Errors during compilation: SkyFox\Supplier\UI\DataProvider\Supplier\DataProvider

Incompatible argument type: Required type: string.

Actual type:\SkyFox\Supplier\UI\DataProvider\Supplier\name;

File: /var/www/html/sky.local/app/code/SkyFox/Supplier/UI/DataProvider/Supplier/DataProvider.php

Total Errors Count: 1 [Magento\Framework\Validator\Exception]
Error during compilation

setup:di:compile

This's my code:

namespace SkyFox\Supplier\Model\Company;

use Magento\Framework\App\Request\DataPersistorInterface;

class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider {

    /**
     * @var \SkyFox\Supplier\Model\ResourceModel\Supplier\Collection
     */
    protected $collection;

    /**
     * @var DataPersistorInterface
     */
    protected $dataPersistor;

    /**
     * @var array
     */
    protected $loadedData;

    /**
     * @var \Magento\Framework\DB\Adapter\AdapterInterface
     */
    protected $connection;

    /**
     * DataProvider constructor.
     * @param $name
     * @param $primaryFieldName
     * @param $requestFieldName
     * @param \SkyFox\Supplier\Model\ResourceModel\Supplier\CollectionFactory $collectionFactory
     * @param DataPersistorInterface $dataPersistor
     * @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
     * @param array $meta
     * @param array $data
     */
    public function __construct(
        $name,
        $primaryFieldName,
        $requestFieldName,
        \SkyFox\Supplier\Model\ResourceModel\Supplier\CollectionFactory $collectionFactory,
        DataPersistorInterface $dataPersistor,
        \Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
        array $meta = [],
        array $data = []
    ) {
        $this->collection = $collectionFactory->create();
        $this->dataPersistor = $dataPersistor;
        $this->connection = $connection;
        parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
    }

    /**
     * @return array
     */
    public function getData()
    {
        if (isset($this->loadedData)) {
            return $this->loadedData;
        }
        $items = $this->collection->getItems();

        foreach ($items as $supplier) {
            $this->loadedData[$supplier->getData('company_id')] = $supplier->getData();
        }

        $data = $this->dataPersistor->get('supplier');
        if (!empty($data)) {
            $supplier = $this->collection->getNewEmptyItem();
            $supplier->setData($data);
            $this->loadedData[$supplier->getData('company_id')] = $supplier->getData();
            $this->dataPersistor->clear('supplier');
        }

        return $this->loadedData;
    }
}

Thanks all

2
  • I don't understand, what's change in new code, how is this error? I get the same error. Can you help me fix it. Thanks. Interception cache generation... 6/7 [========================>---] 85% 3 mins 380.0 MiBErrors during compilation: Sample\Subscribe\Ui\DataProvider\SubscribeToPrice\SubscribeToPriceDataProvider Incompatible argument type: Required type: string. Actual type: \Sample\Subscribe\Model\ResourceModel\SubscribeToPrice\CollectionFactory; File:C:/wamp64/www/Projects/app/code/Sample/Subscribe/Ui/DataProvider/SubscribeToPrice/SubscribeToPriceDataProvider.php Sample\Subscribe\Ui\DataProv Nov 8, 2018 at 10:18
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review Nov 8, 2018 at 11:50

2 Answers 2

36

The error Incompatible argument type: Required type: string. Actual type: \SkyFox\Supplier\UI\DataProvider\Supplier\name; File is triggered because of the missing type in the __construct phpDoc annotation.

So the __construct phpDoc annotation need to be as below:

/**
 * DataProvider constructor.
 * @param string $name
 * @param string $primaryFieldName
 * @param string $requestFieldName
 * @param \SkyFox\Supplier\Model\ResourceModel\Supplier\CollectionFactory $collectionFactory
 * @param DataPersistorInterface $dataPersistor
 * @param array $meta
 * @param array $data
 */
 public function __construct(
     $name,
     $primaryFieldName,
     $requestFieldName,
     \SkyFox\Supplier\Model\ResourceModel\Supplier\CollectionFactory $collectionFactory,
     DataPersistorInterface $dataPersistor,
     array $meta = [],
     array $data = []
) {
     $this->dataPersistor = $dataPersistor;
     $this->connection = $connection;
     parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
   }

Means:

@param $name

@param $primaryFieldName

@param $requestFieldName

Should be

@param string $name

@param string $primaryFieldName

@param string $requestFieldName

For more details check Magento\Ui\DataProvider\AbstractDataProvider class

You can also remove \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, As you are not using it any where on the class.

3
  • 4
    This answer is gold. Jan 13, 2020 at 23:51
  • 4
    So now even comments throw errors. #progress. facepalm
    – Jay Ghosh
    Jun 22, 2021 at 7:12
  • 1
    Faced a similar issue and updating the phpDoc worked for me. Dec 21, 2021 at 11:52
2

Try this:

namespace SkyFox\Supplier\Model\Company;

use Magento\Framework\App\Request\DataPersistorInterface;

class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider {

    /**
     * @var \SkyFox\Supplier\Model\ResourceModel\Supplier\Collection
     */
    protected $collection;

    /**
     * @var DataPersistorInterface
     */
    protected $dataPersistor;

    /**
     * @var array
     */
    protected $loadedData;

    /**
     * @var \Magento\Framework\DB\Adapter\AdapterInterface
     */
    protected $connection;

    /**
     * DataProvider constructor.
     * @param string $name
     * @param string $primaryFieldName
     * @param string $requestFieldName
     * @param \SkyFox\Supplier\Model\ResourceModel\Supplier\CollectionFactory $collectionFactory
     * @param DataPersistorInterface $dataPersistor
     * @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
     * @param array $meta
     * @param array $data
     */
    public function __construct(
        $name,
        $primaryFieldName,
        $requestFieldName,
        \SkyFox\Supplier\Model\ResourceModel\Supplier\CollectionFactory $collectionFactory,
        DataPersistorInterface $dataPersistor,
        \Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
        array $meta = [],
        array $data = []
    ) {
        $this->collection = $collectionFactory->create();
        $this->dataPersistor = $dataPersistor;
        $this->connection = $connection;
        parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
    }

    /**
     * @return array
     */
    public function getData()
    {
        if (isset($this->loadedData)) {
            return $this->loadedData;
        }
        $items = $this->collection->getItems();

        foreach ($items as $supplier) {
            $this->loadedData[$supplier->getData('company_id')] = $supplier->getData();
        }

        $data = $this->dataPersistor->get('supplier');
        if (!empty($data)) {
            $supplier = $this->collection->getNewEmptyItem();
            $supplier->setData($data);
            $this->loadedData[$supplier->getData('company_id')] = $supplier->getData();
            $this->dataPersistor->clear('supplier');
        }

        return $this->loadedData;
    }
}
2

Your Answer

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

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