Today I had to fix the following issue in a custom module. The error appeared on the UI Component list view.
1 |
Fatal error: Method Magento\Ui\TemplateEngine\Xhtml\Result::__toString() must not throw an exception, caught TypeError: Argument 1 passed to Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider::searchResultToOutput() must implement interface Magento\Framework\Api\Search\SearchResultInterface, instance of [Namespace]\[Module]\Model\ResourceModel\Team\Collection given, called in |
I found the reason of the problem in the di.xml file. All what was missing was the following virtualType node. After adding this and re-compiling the code, the list view was fixed.
1 2 3 4 5 6 |
<virtualType name="[Namespace]\[Module]\Model\ResourceModel\Team\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult"> <arguments> <argument name="mainTable" xsi:type="string">[namespace]_[module]_team</argument> <argument name="resourceModel" xsi:type="string">[Namespace]\[Module]\Model\ResourceModel\Team</argument> </arguments> </virtualType> |