1

I have an issue on compile on customs extension:

ImaginationMedia\SocialOrder\Ui\DataProvider\Sales\Order\Donation\DataProvider Incompatible argument type: Required type: string. Actual type: \ImaginationMedia\SocialOrder\Ui\DataProvider\Sales\Order\Donation\name; File: /var/www/html/app/code/ImaginationMedia/SocialOrder/Ui/DataProvider/Sales/Order/Donation/DataProvider.php

Total Errors Count: 1

In Log.php line 92: Error during compilation

<?php

namespace ImaginationMedia\SocialOrder\Ui\DataProvider\Sales\Order\Donation;

use ImaginationMedia\SocialOrder\Model\Helper;
use Magento\Backend\Model\Session;
use Magento\Framework\Api\Filter;
use Magento\Ui\DataProvider\AbstractDataProvider;
use Magento\Ui\DataProvider\AddFieldToCollectionInterface;
use Magento\Ui\DataProvider\AddFilterToCollectionInterface;

class DataProvider extends AbstractDataProvider
{
    /**
     * @var Helper
     */
    private $helper;

    /**
     * @var AddFieldToCollectionInterface[]
     */
    protected $addFieldStrategies;

    /**
     * @var AddFilterToCollectionInterface[]
     */
    protected $addFilterStrategies;

    /**
     * @var int
     */
    private $productId;

    /**
     * DataProvider constructor.
     * @param $name
     * @param $primaryFieldName
     * @param $requestFieldName
     * @param Helper $helper
     * @param Session $session
     * @param array $addFieldStrategies
     * @param array $addFilterStrategies
     * @param array $meta
     * @param array $data
     */
    public function __construct(
        $name,
        $primaryFieldName,
        $requestFieldName,
        Helper $helper,
        Session $session,
        array $addFieldStrategies = [],
        array $addFilterStrategies = [],
        array $meta = [],
        array $data = []
    ) {
        parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
        $this->addFieldStrategies = $addFieldStrategies;
        $this->addFilterStrategies = $addFilterStrategies;
        $this->helper = $helper;
        $this->productId = $session->getCurrentDonationProduct();
    }

    /**
     * @return \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection|\Magento\Sales\Model\ResourceModel\Order\Item\Collection
     */
    public function getCollection()
    {
        return $this->helper->getDonationOrders($this->productId);
    }

    /**
     * Get data
     *
     * @return array
     */
    public function getData()
    {
        $items = $this->getCollection();

        $items = $this->helper->getItemsInArray($items);

        $result = [
            'totalRecords' => $this->getCollection()->getSize(),
            'items' => array_values($items),
        ];
        return $result;
    }

    /**
     * Add field to select
     *
     * @param string $field
     * @param string $alias
     * @return void
     */
    public function addField($field, $alias = null)
    {
        if (isset($this->addFieldStrategies[$field])) {
            $this->addFieldStrategies[$field]->addField($this->getCollection(), $field, $alias);
        } else {
            parent::addField($field, $alias);
        }
    }

    /**
     * {@inheritdoc}
     */
    public function addFilter(Filter $filter)
    {
        if (isset($this->addFilterStrategies[$filter->getField()])) {
            $this->addFilterStrategies[$filter->getField()]
                ->addFilter(
                    $this->getCollection(),
                    $filter->getField(),
                    [$filter->getConditionType() => $filter->getValue()]
                );
        } else {
            parent::addFilter($filter);
        }
    }
  • try * @param string $field * @param string $alias , just remove array and null – fmsthird Apr 23 at 5:06
  • removed null and array & added both @param , same result as previous – Ed Tan Apr 23 at 5:20
  • can you post your whole code DataProvider.php – fmsthird Apr 23 at 5:22
  • updated ,check out code above – Ed Tan Apr 23 at 5:26
1
> /**
>      * DataProvider constructor.
>      * @param $name                          <
>      * @param $primaryFieldName              <
>      * @param $requestFieldName              <
>      * @param Helper $helper
>      * @param Session $session
>      * @param array $addFieldStrategies
>      * @param array $addFilterStrategies
>      * @param array $meta
>      * @param array $data
>      */

I solved my issue by adding 'string'

      * DataProvider constructor.
      * @param string $name
      * @param string $primaryFieldName
      * @param string $requestFieldName

and then clearing Magento's root directory /var/cache and de-compile works

  • thats the same with my answer that i deleted haha anyway it s nice to know it is working now :) – fmsthird Apr 23 at 13:31
0

Try this:

<?php

namespace ImaginationMedia\SocialOrder\Ui\DataProvider\Sales\Order\Donation;

use ImaginationMedia\SocialOrder\Model\Helper;
use Magento\Backend\Model\Session;
use Magento\Framework\Api\Filter;
use Magento\Ui\DataProvider\AbstractDataProvider;
use Magento\Ui\DataProvider\AddFieldToCollectionInterface;
use Magento\Ui\DataProvider\AddFilterToCollectionInterface;

class DataProvider extends AbstractDataProvider
{
    /**
     * @var Helper
     */
    private $helper;

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

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

    /**
     * @var $productId
     */
    private $productId;

    /**
     * DataProvider constructor.
     * @param string|null $name
     * @param $primaryFieldName
     * @param $requestFieldName
     * @param Helper $helper
     * @param Session $session
     * @param array $addFieldStrategies
     * @param array $addFilterStrategies
     * @param array $meta
     * @param array $data
     */
    public function __construct(
        $name,
        $primaryFieldName,
        $requestFieldName,
        Helper $helper,
        Session $session,
        array $addFieldStrategies = [],
        array $addFilterStrategies = [],
        array $meta = [],
        array $data = []
    )
    {
        parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
        $this->addFieldStrategies = $addFieldStrategies;
        $this->addFilterStrategies = $addFilterStrategies;
        $this->helper = $helper;
        $this->productId = $session->getCurrentDonationProduct();
    }

    /**
     * @return mixed
     */
    public function getCollection()
    {
        return $this->helper->getDonationOrders($this->productId);
    }

    /**
     * @return array
     */
    public function getData()
    {
        $items = $this->getCollection();

        $items = $this->helper->getItemsInArray($items);

        $result = [
            'totalRecords' => $this->getCollection()->getSize(),
            'items' => array_values($items),
        ];
        return $result;
    }

    /**
     * @param $field
     * @param null $alias
     */
    public function addField($field, $alias = null)
    {
        if (isset($this->addFieldStrategies[$field])) {
            $this->addFieldStrategies[$field]->addField($this->getCollection(), $field, $alias);
        } else {
            parent::addField($field, $alias);
        }
    }

    /**
     * @param Filter $filter
     */
    public function addFilter(Filter $filter)
    {
        if (isset($this->addFilterStrategies[$filter->getField()])) {
            $this->addFilterStrategies[$filter->getField()]
                ->addFilter(
                    $this->getCollection(),
                    $filter->getField(),
                    [$filter->getConditionType() => $filter->getValue()]
                );
        } else {
            parent::addFilter($filter);
        }
    }
}
  • I tried the code above, cp original as bak.copy whole code and used this and run di compile. Same error – Ed Tan Apr 23 at 5:48
  • try updated answer @EdTan – fmsthird Apr 23 at 6:06
  • what part has changed? – Ed Tan Apr 23 at 6:12
  • 1
    sorry I should have commented it here, I just just set the comment for name to be string and null – fmsthird Apr 23 at 6:14
  • ahh the only difference is I put null on it but i think it should work as well – fmsthird Apr 23 at 13:33

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.