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()));
            }

        }
  • can you change the order of your construct like this: $name, $primaryFieldName, $requestFieldName, OutfitCollectionFactory $outfitCollection, Http $request, SessionManagerInterface $sessionManager, array $meta = [], array $data = [] – fmsthird May 15 at 5:34
  • Problem didn't get solved – Avesh Naik May 15 at 5:43
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.

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

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.