6

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

  • 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 – Chanh Nguyen Nov 8 '18 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 – Murtuza Zabuawala Nov 8 '18 at 11:50
3

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.

1

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;
    }
}
  • @NguyễnHoàngTuấn Great, happy to help you, please accept the answer so it will help others. – kunj Aug 15 '18 at 8:30
  • @NguyễnHoàngTuấn, please click on right symbol. – kunj Aug 20 '18 at 5:01
  • 1
    just to clarify, the error is triggered because of the missing type in the __construct phpDoc annotation. @param $name should be @param string $name – Radu Aug 30 '19 at 13:58

Your Answer

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

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