1

I have this module enabled, and when I try to run setup:di:compile I get this error

Fatal error: Declaration of Mirasvit\Helpdesk\Ui\Component\DataProvider\FulltextFilter::apply() must be compatible with Magento\Framework\View\Element\UiComponent\DataProvider\FilterApplierInterface::apply(Magento\Framework\Data\Collection $collection, Magento\Framework\Api\Filter $filter) in /home/magento2/public_html/app/code/Mirasvit/Helpdesk/Ui/Component/DataProvider/FulltextFilter.php on line 27

This is the original Magento 2 class

namespace Magento\Framework\View\Element\UiComponent\DataProvider;

use Magento\Framework\Data\Collection\AbstractDb;


interface FilterApplierInterface
{
    public function apply(AbstractDb $collection, \Magento\Framework\Api\Filter $filters);
}

And this is the extended class in module

namespace Mirasvit\Helpdesk\Ui\Component\DataProvider;

use Magento\Framework\Data\Collection\AbstractDb as DbCollection;
use Magento\Framework\Api\Filter;


class FulltextFilter implements \Magento\Framework\View\Element\UiComponent\DataProvider\FilterApplierInterface
{

    protected function getFulltextIndexColumns(DbCollection $collection, $indexTable)
    {
        $indexes = $collection->getConnection()->getIndexList($indexTable);
        foreach ($indexes as $index) {
            if (strtoupper($index['INDEX_TYPE']) == 'FULLTEXT') {
                return $index['COLUMNS_LIST'];
            }
        }

        return [];
    }

    public function apply(DbCollection $collection, Filter $filter)
    {
        $columns = $this->getFulltextIndexColumns($collection, $collection->getMainTable());
        if (!$columns) {
            return;
        }
        $collection->getSelect()
            ->where(
                'MATCH('.implode(',', $columns).') AGAINST(?)',
                $filter->getValue()
            );
    }
}

What could be causing this issue?

0

Ryan H, Thank you for your answer, it helped me to find out the real issue,

I had Magento 2.0.7 code base on my development and Magento 2.1 on my server, so the specific core Magento file looked differnt

namespace Magento\Framework\View\Element\UiComponent\DataProvider;

    use Magento\Framework\Api\Filter;
    use Magento\Framework\Data\Collection;

    interface FilterApplierInterface
    {
        public function apply(Collection $collection, Filter $filter);
    }

This is how it looked like on Magento 2.1, so I changed my module code to be look like this

public function apply(\Magento\Framework\Data\Collection $collection, \Magento\Framework\Api\Filter $filter)
{
        $columns = $this->getFulltextIndexColumns($collection, $collection->getMainTable());
        if (!$columns) {
            return;
        }
        $collection->getSelect()
            ->where(
                'MATCH('.implode(',', $columns).') AGAINST(?)',
                $filter->getValue()
            );
}

and it solved the problem for me.

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.