Skip to content

Execute filtering only when a collection is passed to the data source… #25383

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

Open
wants to merge 3 commits into
base: 2.4-develop
Choose a base branch
from
Open
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
61 changes: 40 additions & 21 deletions app/code/Magento/Ui/DataProvider/AbstractDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface;

/**
* Abstract class AbstractDataProvider
*
* @api
* @since 100.0.2
*/
Expand Down Expand Up @@ -36,6 +38,8 @@ abstract class AbstractDataProvider implements DataProviderInterface, \Countable
protected $requestFieldName;

/**
* Data Provider meta
*
* @var array
*/
protected $meta = [];
Expand All @@ -48,16 +52,20 @@ abstract class AbstractDataProvider implements DataProviderInterface, \Countable
protected $data = [];

/**
* Provider collection
*
* @var AbstractCollection
*/
protected $collection;

/**
* AbstractDataProvider constructor
*
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param array $meta
* @param array $data
* @param array $meta
* @param array $data
*/
public function __construct(
$name,
Expand All @@ -74,6 +82,8 @@ public function __construct(
}

/**
* Get collection
*
* @return AbstractCollection
*/
public function getCollection()
Expand Down Expand Up @@ -112,6 +122,8 @@ public function getRequestFieldName()
}

/**
* Get meta
*
* @return array
*/
public function getMeta()
Expand All @@ -122,7 +134,7 @@ public function getMeta()
/**
* Get field Set meta info
*
* @param string $fieldSetName
* @param string $fieldSetName
* @return array
*/
public function getFieldSetMetaInfo($fieldSetName)
Expand All @@ -131,7 +143,9 @@ public function getFieldSetMetaInfo($fieldSetName)
}

/**
* @param string $fieldSetName
* Get fields meta info
*
* @param string $fieldSetName
* @return array
*/
public function getFieldsMetaInfo($fieldSetName)
Expand All @@ -140,8 +154,10 @@ public function getFieldsMetaInfo($fieldSetName)
}

/**
* @param string $fieldSetName
* @param string $fieldName
* Get field meta info
*
* @param string $fieldSetName
* @param string $fieldName
* @return array
*/
public function getFieldMetaInfo($fieldSetName, $fieldName)
Expand All @@ -156,10 +172,13 @@ public function getFieldMetaInfo($fieldSetName, $fieldName)
*/
public function addFilter(\Magento\Framework\Api\Filter $filter)
{
$this->getCollection()->addFieldToFilter(
$filter->getField(),
[$filter->getConditionType() => $filter->getValue()]
);
$collection = $this->getCollection();
if ($collection) {
$collection->addFieldToFilter(
$filter->getField(),
[$filter->getConditionType() => $filter->getValue()]
);
}
}

/**
Expand Down Expand Up @@ -187,8 +206,8 @@ public function getSearchResult()
/**
* Add field to select
*
* @param string|array $field
* @param string|null $alias
* @param string|array $field
* @param string|null $alias
* @return void
*/
public function addField($field, $alias = null)
Expand All @@ -197,10 +216,10 @@ public function addField($field, $alias = null)
}

/**
* self::setOrder() alias
* Add ORDER BY to the end or to the beginning - self::setOrder() alias
*
* @param string $field
* @param string $direction
* @param string $field
* @param string $direction
* @return void
*/
public function addOrder($field, $direction)
Expand All @@ -211,8 +230,8 @@ public function addOrder($field, $direction)
/**
* Set Query limit
*
* @param int $offset
* @param int $size
* @param int $offset
* @param int $size
* @return void
*/
public function setLimit($offset, $size)
Expand All @@ -224,8 +243,8 @@ public function setLimit($offset, $size)
/**
* Removes field from select
*
* @param string|null $field
* @param bool $isAlias Alias identifier
* @param string|null $field
* @param bool $isAlias Alias identifier
* @return void
*/
public function removeField($field, $isAlias = false)
Expand Down Expand Up @@ -276,7 +295,7 @@ public function getConfigData()
/**
* Set data
*
* @param mixed $config
* @param mixed $config
* @return void
*/
public function setConfigData($config)
Expand All @@ -288,7 +307,7 @@ public function setConfigData($config)
* Retrieve all ids from collection
*
* @return int[]
* @since 100.2.0
* @since 100.2.0
*/
public function getAllIds()
{
Expand Down