Skip to content
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

For "updated gii JSON form config path creates two bugs #277" #278

Merged
merged 2 commits into from
Feb 3, 2021
Merged
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: 3 additions & 3 deletions src/generators/crud/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use schmunk42\giiant\helpers\SaveForm;

/*
/**
* @var yii\web\View
* @var yii\bootstrap\ActiveForm $form
* @var schmunk42\giiant\generators\crud\Generator $generator
Expand All @@ -13,10 +13,10 @@
* on chenging listbox, form fill with selected saved forma data
* currently work with input text, input checkbox and select form fields
*/
$this->registerJs(SaveForm::getSavedFormsJs($generator->getName()), yii\web\View::POS_END);
$this->registerJs(SaveForm::getSavedFormsJs($generator->getName(), $generator->giiInfoPath), yii\web\View::POS_END);
$this->registerJs(SaveForm::jsFillForm(), yii\web\View::POS_END);
echo $form->field($generator, 'savedForm')->dropDownList(
SaveForm::getSavedFormsListbox($generator->getName()), ['onchange' => 'fillForm(this.value)']
SaveForm::getSavedFormsListbox($generator->getName(), $generator->giiInfoPath), ['onchange' => 'fillForm(this.value)']
);

echo $form->field($generator, 'modelClass');
Expand Down
4 changes: 2 additions & 2 deletions src/generators/model/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
* on chenging listbox, form fill with selected saved forma data
* currently work with input text, input checkbox and select form fields
*/
$this->registerJs(SaveForm::getSavedFormsJs($generator->getName()), yii\web\View::POS_END);
$this->registerJs(SaveForm::getSavedFormsJs($generator->getName(), $generator->giiInfoPath), yii\web\View::POS_END);
$this->registerJs(SaveForm::jsFillForm(), yii\web\View::POS_END);
echo $form->field($generator, 'savedForm')->dropDownList(
SaveForm::getSavedFormsListbox($generator->getName()), ['onchange' => 'fillForm(this.value)']
SaveForm::getSavedFormsListbox($generator->getName() , $generator->giiInfoPath), ['onchange' => 'fillForm(this.value)']
);

echo $form->field($generator, 'tableName');
Expand Down
19 changes: 10 additions & 9 deletions src/helpers/SaveForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace schmunk42\giiant\helpers;

use yii\helpers\Json;
use yii\helpers\StringHelper;

class SaveForm
Expand Down Expand Up @@ -36,7 +37,7 @@ public static function getFormAttributesValues($generator, $attributes)
* @return array|bool
* @throws \ReflectionException
*/
public static function loadSavedForms($generatorName)
public static function loadSavedForms($generatorName, $giiInfoPath)
{
$suffix = str_replace(' ', '', $generatorName);

Expand All @@ -48,8 +49,8 @@ public static function loadSavedForms($generatorName)
* get all possible gii directories with out validation on existing
*/
$forms = [];
self::buildJson(\Yii::getAlias('@app/gii'), $forms, $suffix, 'app');
if ($commonGiiDir = \Yii::getAlias('@common/gii', false)) {
self::buildJson(\Yii::getAlias('@app/' . $giiInfoPath), $forms, $suffix, 'app');
if ($commonGiiDir = \Yii::getAlias('@common/' . $giiInfoPath, false)) {
self::buildJson($commonGiiDir, $forms, $suffix, 'common');
}
foreach (\Yii::$app->modules as $moduleId => $module) {
Expand All @@ -66,7 +67,7 @@ public static function loadSavedForms($generatorName)
$reflector = new \ReflectionClass($module['class']);
$basePath = StringHelper::dirname($reflector->getFileName());
}
$basePath .= '/gii';
$basePath .= '/' . $giiInfoPath;

self::buildJson($basePath, $forms, $suffix, $moduleId);
}
Expand Down Expand Up @@ -109,10 +110,10 @@ protected static function buildJson($path, &$forms, $suffix, $moduleId = NULL)
*
* @return array
*/
public static function getSavedFormsListbox($generatorName)
public static function getSavedFormsListbox($generatorName, $giiInfoPath)
{
$r = ['0' => ' - '];
foreach (self::loadSavedForms($generatorName) as $k => $row) {
foreach (self::loadSavedForms($generatorName, $giiInfoPath) as $k => $row) {
$r[$k] = $row['label'];
}

Expand All @@ -124,12 +125,12 @@ public static function getSavedFormsListbox($generatorName)
*
* @return string
*/
public static function getSavedFormsJs($generatorName)
public static function getSavedFormsJs($generatorName, $giiInfoPath)
{
$js = [];

foreach (self::loadSavedForms($generatorName) as $k => $row) {
$js[] = $k.":'".$row['jsonData']."'";
foreach (self::loadSavedForms($generatorName, $giiInfoPath) as $k => $row) {
$js[] = $k.":'".Json::encode(Json::decode($row['jsonData']))."'";
}

return 'var savedForms = {'.str_replace('\\', '\\\\', implode(',', $js)).'};';
Expand Down