Skip to content

Execute collection tasks only when a valid collection is passed to th… #13574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/code/Magento/Ui/Component/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we don't need invoking $this->getContext()->getDataProvider() once again since we have added $dataProvider variable

->addFilter($filter);
}

$data = $this->getContext()->getDataProvider()->getData();

Expand Down
16 changes: 16 additions & 0 deletions app/code/Magento/Ui/DataProvider/AbstractDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
24 changes: 15 additions & 9 deletions app/code/Magento/Ui/Test/Unit/Component/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down