Magento 2 Coding standard provide me Warning
My Code is here
namespace Namespace\Modulename\Model;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Ui\DataProvider\AbstractDataProvider;
use Namespace\Modulename\Model\ResourceModel\Customoption\CollectionFactory;
class CustomoptionProvider extends AbstractDataProvider
{
public $collection;
public $dataPersistor;
public $loadedData;
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
CollectionFactory $pageCollectionFactory,
DataPersistorInterface $dataPersistor,
array $meta = [],
array $data = []
) {
$this->collection = $pageCollectionFactory->create();
$this->dataPersistor = $dataPersistor;
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
}
public function getData()
{
if (isset($this->loadedData)) {
return $this->loadedData;
}
$items = $this->collection->getItems();
foreach ($items as $page) {
...
}
$data = $this->dataPersistor->get('module_messages');
if (!empty($data)) {
$page = $this->collection->getNewEmptyItem();
$page->setData($data);
$this->loadedData[$page->getId()] = $page->getData();
$this->dataPersistor->clear('module_messages');
}
return $this->loadedData;
}
}
I had use this
$this->collection = $pageCollectionFactory;
$this->collection = $this->collection->create();
but it provide me error
Fatal error: Method Magento\Ui\TemplateEngine\Xhtml\Result::__toString() must not throw an exception, caught Error: Call to undefined method Namespace\Modulename\Model\ResourceModel\Customoption\CollectionFactory::addFieldToFilter() in D:\xampp72\htdocs\mage231\vendor\magento\module-ui\Component\Wrapper\UiComponent.php on line 0
if have any solution then provide for this issue.