18

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 Commented 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 Commented Nov 8, 2018 at 11:50

3 Answers 3

40

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. Commented Jan 13, 2020 at 23:51
  • 4
    So now even comments throw errors. #progress. facepalm Commented Jun 22, 2021 at 7:12
  • 1
    Faced a similar issue and updating the phpDoc worked for me. Commented 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
  • 2
    just to clarify, the error is triggered because of the missing type in the __construct phpDoc annotation. @param $name should be @param string $name Commented Aug 30, 2019 at 13:58
  • Facing same issue. Any idea on this. magento.stackexchange.com/questions/365278/… Commented Mar 11, 2023 at 10:35
0

other workaround

public function __construct( string $name, string $primaryFieldName, 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.