Skip to content

Commit

Permalink
Merge pull request #210 from luyadev/new-active-query-select-injector
Browse files Browse the repository at this point in the history
active query select injector
  • Loading branch information
nadar authored Jul 11, 2019
2 parents 2c99319 + f6fa1fa commit 7039aec
Show file tree
Hide file tree
Showing 24 changed files with 228 additions and 66 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
In order to read more about upgrading and BC breaks have a look at the [UPGRADE Document](UPGRADE.md).

## 2.0.1
## 2.1.0

### Added

+ [#210](https://github.com/luyadev/luya-module-cms/pull/210) Added new Active Query Select Injector class.

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"issues" : "https://github.com/luyadev/luya-module-cms/issues"
},
"require-dev" : {
"luyadev/luya-testsuite" : "^1.0@dev",
"luyadev/luya-testsuite" : "^1.0",
"twbs/bootstrap": "~4.3.0",
"unglue/client": "^1.3"
},
Expand Down
28 changes: 13 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/admin/apis/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function actionControllerActions($module, $controller)

/**
* Get actions for a given controller.
*
*
* @param object $controller
* @since 2.0.0
* @see Replace with luya core object helper
Expand Down
26 changes: 13 additions & 13 deletions src/admin/apis/NavController.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,16 @@ public function actionCreateModule()
}

$create = $model->createModule(
$parentNavId,
$navContainerId,
$this->postArg('lang_id'),
$this->postArg('title'),
$this->postArg('alias'),
$this->postArg('module_name'),
$parentNavId,
$navContainerId,
$this->postArg('lang_id'),
$this->postArg('title'),
$this->postArg('alias'),
$this->postArg('module_name'),
$this->postArg('description'),
$this->postArg('controller_name'),
$this->postArg('action_name'),
$this->postArg('action_params', [])
$this->postArg('controller_name'),
$this->postArg('action_name'),
$this->postArg('action_params', [])
);
if (is_array($create)) {
Yii::$app->response->statusCode = 422;
Expand All @@ -368,12 +368,12 @@ public function actionCreateModuleItem()
$create = $model->createModuleItem(
$this->postArg('nav_id'),
$this->postArg('lang_id'),
$this->postArg('title'),
$this->postArg('alias'),
$this->postArg('title'),
$this->postArg('alias'),
$this->postArg('module_name'),
$this->postArg('description'),
$this->postArg('controller_name'),
$this->postArg('action_name'),
$this->postArg('controller_name'),
$this->postArg('action_name'),
$this->postArg('action_params', [])
);
if (is_array($create)) {
Expand Down
4 changes: 2 additions & 2 deletions src/admin/apis/RedirectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class RedirectController extends \luya\admin\ngrest\base\Api

/**
* Find a redirect object for a given path info.
*
*
* An example using path would be: Yii::$app->request->pathInfo
*
*
* url: https://example.com/hello/world
* path: hello/world
*
Expand Down
1 change: 0 additions & 1 deletion src/admin/importers/BlockImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ protected function handleBlockDefintionInDirectories(array $directories, $blockD
{
$results = [];
foreach ($directories as $directoryPath) {

$path = rtrim($directoryPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($blockDefinition, DIRECTORY_SEPARATOR);

$path = $this->replaceDsSeparator($path);
Expand Down
2 changes: 1 addition & 1 deletion src/admin/importers/CmslayoutImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ protected function importLayoutFile($file, $aliased)
}

return $layoutItem->id;
}
}

// add item into the database table
$data = new Layout();
Expand Down
2 changes: 1 addition & 1 deletion src/admin/messages/ru/cmsadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
'menu_group_item_env_container' => 'Контейнеры',
'menu_group_item_env_layouts' => 'Макеты',
'menu_group_elements' => 'Элементы контента',
'menu_group_item_elements_blocks' => 'Блоки',
'menu_group_item_elements_blocks' => 'Блоки',
'menu_group_item_elements_group' => 'Группы блоков',
'btn_abort' => 'Отмена',
'btn_refresh' => 'Обновить',
Expand Down
6 changes: 3 additions & 3 deletions src/base/BlockInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,17 @@ public function getIsDirtyDialogEnabled();

/**
* This method is called whenever a block inside a placeholder is rendered.
*
*
* This allows you to change the render behavior of every block inside a placeholder. An example of
* adding a wrapper div to the iteration:
*
*
* ```php
* public function placeholderRenderIteration(BlockInterface $block)
* {
* return '<div class="block-wrapper">'.$block->renderFrontend().'</div>';
* }
* ```
*
*
* This also allows you to determined whether the block should be rendered or not as the response is the content
* of the block inside the placholder.
*
Expand Down
7 changes: 4 additions & 3 deletions src/base/InternalBaseBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ public function getExtraValue($key, $default = false)
$this->getExtraVarValues();
$this->_assignExtraVars = true;
}
return (isset($this->_extraVars[$key])) ? $this->_extraVars[$key] : $default;

return isset($this->_extraVars[$key]) ? $this->_extraVars[$key] : $default;
}

/**
Expand Down Expand Up @@ -483,7 +484,7 @@ public function addVar(array $varConfig, $append = false)
*/
public function getConfigPlaceholdersExport()
{
$array = (array_key_exists('placeholders', $this->config())) ? $this->config()['placeholders'] : [];
$array = array_key_exists('placeholders', $this->config()) ? $this->config()['placeholders'] : [];

$holders = [];

Expand All @@ -505,7 +506,7 @@ public function getConfigPlaceholdersExport()
*/
public function getConfigPlaceholdersByRowsExport()
{
$array = (array_key_exists('placeholders', $this->config())) ? $this->config()['placeholders'] : [];
$array = array_key_exists('placeholders', $this->config()) ? $this->config()['placeholders'] : [];

$rows = [];

Expand Down
1 change: 0 additions & 1 deletion src/frontend/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public function bootstrap($app)
// handle not found exceptions
$app->errorHandler->on(ErrorHandler::EVENT_BEFORE_EXCEPTION_RENDER, function (ErrorHandlerExceptionRenderEvent $event) use ($app) {
if ($event->exception instanceof NotFoundHttpException) {

$errorPageNavId = Config::get(Config::HTTP_EXCEPTION_NAV_ID, 0);
/** @var $item Item */
$item = $app->menu->find()->with(['hidden'])->where(['nav_id' => $errorPageNavId])->one();
Expand Down
2 changes: 0 additions & 2 deletions src/frontend/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,4 @@ protected function findInternalRedirect()

return false;
}


}
12 changes: 5 additions & 7 deletions src/injectors/ActiveQueryRadioInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,30 @@

namespace luya\cms\injectors;

use yii\db\ActiveQueryInterface;
use yii\data\ActiveDataProvider;
use luya\admin\base\TypesInterface;

/**
* Checkboxes from an ActiveQuery.
* Radio List from an ActiveQuery.
*
* Generates a checkbox selection from an active query interface and returns the
* Generates a radio selection from an active query interface and returns the
* models via the ActiveDataProvider.
*
* An example for the injector config:
*
* ```php
* new ActiveQueryCheckboxInjector([
* new ActiveQueryRadioInjector([
* '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 ActiveQueryCheckboxInjector used the {{\luya\cms\base\InternalBaseBlock::injectors}} method:
* In order to configure the ActiveQueryRadioInjector used the {{\luya\cms\base\InternalBaseBlock::injectors}} method:
*
* ```php
* public function injectors()
* {
* return [
* 'theData' => new ActiveQueryCheckboxInjector([
* 'theData' => new ActiveQueryRadioInjector([
* 'query' => News::find()->where(['is_deleted' => 0]),
* 'label' => function($model) {
* return $model->title . " - " . $model->description;
Expand Down
61 changes: 61 additions & 0 deletions src/injectors/ActiveQuerySelectInjector.php
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());
}
}
Loading

0 comments on commit 7039aec

Please sign in to comment.