-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #210 from luyadev/new-active-query-select-injector
active query select injector
- Loading branch information
Showing
24 changed files
with
228 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,4 @@ protected function findInternalRedirect() | |
|
||
return false; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace luya\cms\injectors; | ||
|
||
use luya\admin\base\TypesInterface; | ||
|
||
/** | ||
* Select List from an ActiveQuery. | ||
* | ||
* Generates a Select selection from an active query interface and returns the | ||
* models via the ActiveDataProvider. | ||
* | ||
* An example for the injector config: | ||
* | ||
* ```php | ||
* new ActiveQuerySelectInjector([ | ||
* 'query' => \newsadmin\models\Article::find()->where(['cat_id' => 1]), | ||
* 'label' => 'title', // This attribute from the model is used to render the admin block dropdown selection. | ||
* ]); | ||
* ``` | ||
* | ||
* In order to configure the ActiveQuerySelectInjector used the {{\luya\cms\base\InternalBaseBlock::injectors}} method: | ||
* | ||
* ```php | ||
* public function injectors() | ||
* { | ||
* return [ | ||
* 'theData' => new ActiveQuerySelectInjector([ | ||
* 'query' => News::find()->where(['is_deleted' => 0]), | ||
* 'label' => function($model) { | ||
* return $model->title . " - " . $model->description; | ||
* }, | ||
* ]); | ||
* ]; | ||
* } | ||
* ``` | ||
* | ||
* @property \yii\db\ActiveQueryInterface $query The ActiveQuery object | ||
* | ||
* @author Basil Suter <[email protected]> | ||
* @since 2.1.0 | ||
*/ | ||
class ActiveQuerySelectInjector extends BaseActiveQueryInjector | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setup() | ||
{ | ||
// injecto the config | ||
$this->setContextConfig([ | ||
'var' => $this->varName, | ||
'type' => TypesInterface::TYPE_SELECT, | ||
'label' => $this->varLabel, | ||
'options' => $this->getQueryData(), | ||
]); | ||
|
||
// provide the extra data | ||
$this->context->addExtraVar($this->varName, $this->getExtraAssignSingleData()); | ||
} | ||
} |
Oops, something went wrong.