diff --git a/app/code/Magento/Ui/Component/Form.php b/app/code/Magento/Ui/Component/Form.php index 4033abba820e0..8bcf4c774624a 100644 --- a/app/code/Magento/Ui/Component/Form.php +++ b/app/code/Magento/Ui/Component/Form.php @@ -63,8 +63,10 @@ public function getDataSourceData() $filter = $this->filterBuilder->setField($this->getContext()->getDataProvider()->getPrimaryFieldName()) ->setValue($id) ->create(); - $this->getContext()->getDataProvider() - ->addFilter($filter); + if ($this->getContext()->getDataProvider()->useCollection()) { + $this->getContext()->getDataProvider() + ->addFilter($filter); + } $data = $this->getContext()->getDataProvider()->getData(); diff --git a/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php b/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php index cff6171395ec9..5446c84c4c53a 100644 --- a/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php +++ b/app/code/Magento/Ui/DataProvider/AbstractDataProvider.php @@ -294,4 +294,20 @@ public function getAllIds() { return $this->collection->getAllIds(); } + + /** + * Check configuration looking for a no-collection usage + * + * @return bool + */ + public function useCollection() + { + $configData = $this->getConfigData(); + + if (isset($configData['noCollection']) && $configData['noCollection']) { + return false; + } + + return true; + } } diff --git a/app/code/Magento/Ui/Test/Unit/Component/FormTest.php b/app/code/Magento/Ui/Test/Unit/Component/FormTest.php index 6951583291df9..7fbd0960b7777 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/FormTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/FormTest.php @@ -93,9 +93,11 @@ public function testGetDataSourceData() ->method('create') ->willReturn($filterMock); - $dataProviderMock->expects($this->once()) - ->method('addFilter') - ->with($filterMock); + if ($dataProviderMock->useCollection()) { + $dataProviderMock->expects($this->once()) + ->method('addFilter') + ->with($filterMock); + } $dataProviderMock->expects($this->once()) ->method('getData') ->willReturn($data); @@ -147,9 +149,11 @@ public function testGetDataSourceDataWithoutData() ->method('create') ->willReturn($filterMock); - $dataProviderMock->expects($this->once()) - ->method('addFilter') - ->with($filterMock); + if ($dataProviderMock->useCollection()) { + $dataProviderMock->expects($this->once()) + ->method('addFilter') + ->with($filterMock); + } $dataProviderMock->expects($this->once()) ->method('getData') ->willReturn($data); @@ -206,9 +210,11 @@ public function testGetDataSourceDataWithoutId() ->method('create') ->willReturn($filterMock); - $dataProviderMock->expects($this->once()) - ->method('addFilter') - ->with($filterMock); + if ($dataProviderMock->useCollection()) { + $dataProviderMock->expects($this->once()) + ->method('addFilter') + ->with($filterMock); + } $dataProviderMock->expects($this->once()) ->method('getData') ->willReturn($data);