Skip to content

Commit

Permalink
enhance data provider config usage
Browse files Browse the repository at this point in the history
  • Loading branch information
nateiler committed Jan 11, 2019
1 parent a0e230d commit 8332ba4
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/actions/IndexTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace flipbox\craft\ember\actions;

use craft\helpers\ArrayHelper;
use flipbox\craft\ember\helpers\ObjectHelper;
use yii\data\ActiveDataProvider;
use yii\data\DataProviderInterface;
Expand All @@ -27,9 +28,10 @@ trait IndexTrait
public $dataProvider = [];

/**
* @param array $config
* @return QueryInterface
*/
abstract protected function createQuery(): QueryInterface;
abstract protected function createQuery(array $config = []): QueryInterface;

/**
* @return DataProviderInterface
Expand Down Expand Up @@ -71,16 +73,22 @@ protected function performAction(DataProviderInterface $dataProvider): DataProvi
}

/**
* @param array $config
* @return DataProviderInterface
* @throws \yii\base\InvalidConfigException
*/
protected function createDataProvider(): DataProviderInterface
protected function createDataProvider(array $config = []): DataProviderInterface
{
$queryConfig = (array) ArrayHelper::remove($config, 'query', []);

/** @var DataProviderInterface $dataProvider */
$dataProvider = ObjectHelper::create(
$this->dataProviderConfig([
'query' => $this->createQuery()
]),
$this->dataProviderConfig(ArrayHelper::merge(
[
'query' => $this->createQuery($queryConfig)
],
$config
)),
DataProviderInterface::class
);

Expand Down

0 comments on commit 8332ba4

Please sign in to comment.