3

After running bin/magento setup:di:compile I get the following error.

Errors during compilation:

Vendor\Module\Ui\Component\DataProvider\OutfitProvider Incompatible argument type: Required type: string. Actual type: \Allure\Celebrities\Ui\Component\DataProvider\name; File: /var/www/vhosts/phoenix/app/code/Vendor/Module/Ui/Component/DataProvider/OutfitProvider.php

Here is the code on Ui listing

<dataSource name="outfit_listing_data_source">
 <argument name="dataProvider" xsi:type="configurableObject">
 <argument name="class" xsi:type="string">Vendor\Module\Ui\Component\DataProvider\OutfitProvider</argument>
 <argument name="name" xsi:type="string">outfit_listing_data_source</argument>
 <argument name="primaryFieldName" xsi:type="string">celebrity_outfit_id</argument>
 <argument name="requestFieldName" xsi:type="string">id</argument>
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="update_url" xsi:type="url" path="mui/index/render"/>
 </item>
 </argument>
 </argument>
 <argument name="data" xsi:type="array">
 <item name="js_config" xsi:type="array">
 <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
 </item>
 </argument>
</dataSource>

Class

 use Magento\Ui\DataProvider\AbstractDataProvider;
 use Magento\Framework\App\Request\Http;
 use Vendor\Module\Model\ResourceModel\Outfit\CollectionFactory as OutfitCollectionFactory;
 use Magento\Framework\Session\SessionManagerInterface;
 use Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface;
 class OutfitProvider extends AbstractDataProvider implements DataProviderInterface
 {
 protected $_outfitCollection;
 protected $_request;
 protected $_sessionManger;
 public function __construct(
 $name,
 $primaryFieldName,
 $requestFieldName,
 array $meta = [],
 array $data = [],
 OutfitCollectionFactory $outfitCollection,
 Http $request,
 SessionManagerInterface $sessionManager
 ) {
 parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
 $this->_request = $request;
 $this->_sessionManger = $sessionManager;
 $this->_outfitCollection = $outfitCollection;
 $this->initCollection();
 }
 public function initCollection()
 {
 $id = $this->_request->getParam("id");
 if(isset($id))
 {
 $this->_sessionManger->setCelebrityId($id);
 }
 $collection = $this->_outfitCollection->create();
 $this->collection = $collection;
 $this->collection->addFieldToFilter("celebrity_id", array("eq" => $this->_sessionManger->getCelebrityId()));
 }
 }
Ghulam.M
9738 silver badges25 bronze badges
asked May 15, 2019 at 5:25
2
  • can you change the order of your construct like this: $name, $primaryFieldName, $requestFieldName, OutfitCollectionFactory $outfitCollection, Http $request, SessionManagerInterface $sessionManager, array $meta = [], array $data = [] Commented May 15, 2019 at 5:34
  • Problem didn't get solved Commented May 15, 2019 at 5:43

1 Answer 1

2

add the docblock to the __construct method and type hint as string the following $name, $primaryFieldName, $requestFieldName.

/**
 * @param string $name
 * @param string $primaryFieldName
 * @param string $requestFieldName
 * @param array $meta
 * @param array $data
 * @param OutfitCollectionFactory $outfitCollection
 * @param Http $request
 * @param SessionManagerInterface $sessionManager
 */

Also, your constructor parameters with default values should be added last.

answered May 15, 2019 at 5:30
7
  • Didn't worked Is anything i am missing? Commented May 15, 2019 at 5:50
  • 2
    Strange. That was usually the problem for me. Commented May 15, 2019 at 5:58
  • Previously it was showing error two times. Now only once. I am developing on 2.3 Commented May 15, 2019 at 6:04
  • Did i done right thing in ui listing file ? Commented May 15, 2019 at 6:05
  • aha...maybe there is one other data provider or other class with the same issue. Commented May 15, 2019 at 6:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.