Commit c0b5af30 by Carsten Brandt

Merge pull request #2836 from lucianobaraglia/gii-i18n-model

Enable I18N for GII model generator
parents e14ab8be 7a376175
......@@ -115,9 +115,9 @@ yii.gii = (function ($) {
$('#model-generator .field-generator-modelclass').toggle($(this).val().indexOf('*') == -1);
}).change();
// CRUD generator: hide messageCategory when I18N is disabled
$('#crud-generator #generator-enablei18n').change(function () {
$('#crud-generator .field-generator-messagecategory').toggle($(this).is(':checked'));
// hide message category when I18N is disabled
$('form #generator-enablei18n').change(function () {
$('form .field-generator-messagecategory').toggle($(this).is(':checked'));
}).change();
// hide Generate button if any input is changed
......
......@@ -70,6 +70,8 @@ class Generator extends \yii\gii\Generator
[['viewPath'], 'match', 'pattern' => '/^@?\w+[\\-\\/\w]*$/', 'message' => 'Only word characters, dashes, slashes and @ are allowed.'],
[['viewPath'], 'validateViewPath'],
[['scenarioName'], 'match', 'pattern' => '/^[\w\\-]+$/', 'message' => 'Only word characters and dashes are allowed.'],
[['enableI18N'], 'boolean'],
[['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false],
]);
}
......@@ -78,12 +80,12 @@ class Generator extends \yii\gii\Generator
*/
public function attributeLabels()
{
return [
return array_merge(parent::attributeLabels(), [
'modelClass' => 'Model Class',
'viewName' => 'View Name',
'viewPath' => 'View Path',
'scenarioName' => 'Scenario',
];
]);
}
/**
......@@ -99,7 +101,7 @@ class Generator extends \yii\gii\Generator
*/
public function stickyAttributes()
{
return ['viewPath', 'scenarioName'];
return array_merge(parent::stickyAttributes(), ['viewPath', 'scenarioName']);
}
/**
......@@ -107,12 +109,12 @@ class Generator extends \yii\gii\Generator
*/
public function hints()
{
return [
return array_merge(parent::hints(), [
'modelClass' => 'This is the model class for collecting the form input. You should provide a fully qualified class name, e.g., <code>app\models\Post</code>.',
'viewName' => 'This is the view name with respect to the view path. For example, <code>site/index</code> would generate a <code>site/index.php</code> view file under the view path.',
'viewPath' => 'This is the root view path to keep the generated view files. You may provide either a directory or a path alias, e.g., <code>@app/views</code>.',
'scenarioName' => 'This is the scenario to be used by the model when collecting the form input. If empty, the default scenario will be used.',
];
]);
}
/**
......
......@@ -28,7 +28,7 @@ use yii\widgets\ActiveForm;
<?php endforeach; ?>
<div class="form-group">
<?= "<?= " ?>Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
<?= "<?= " ?>Html::submitButton(<?= $generator->generateString('Submit') ?>, ['class' => 'btn btn-primary']) ?>
</div>
<?= "<?php " ?>ActiveForm::end(); ?>
......
......@@ -8,3 +8,5 @@ echo $form->field($generator, 'viewName');
echo $form->field($generator, 'modelClass');
echo $form->field($generator, 'scenarioName');
echo $form->field($generator, 'viewPath');
echo $form->field($generator, 'enableI18N')->checkbox();
echo $form->field($generator, 'messageCategory');
......@@ -64,6 +64,8 @@ class Generator extends \yii\gii\Generator
[['modelClass'], 'validateModelClass', 'skipOnEmpty' => false],
[['baseClass'], 'validateClass', 'params' => ['extends' => ActiveRecord::className()]],
[['generateRelations', 'generateLabelsFromComments'], 'boolean'],
[['enableI18N'], 'boolean'],
[['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false],
]);
}
......@@ -72,7 +74,7 @@ class Generator extends \yii\gii\Generator
*/
public function attributeLabels()
{
return [
return array_merge(parent::attributeLabels(), [
'ns' => 'Namespace',
'db' => 'Database Connection ID',
'tableName' => 'Table Name',
......@@ -80,7 +82,7 @@ class Generator extends \yii\gii\Generator
'baseClass' => 'Base Class',
'generateRelations' => 'Generate Relations',
'generateLabelsFromComments' => 'Generate Labels from DB Comments',
];
]);
}
/**
......@@ -88,7 +90,7 @@ class Generator extends \yii\gii\Generator
*/
public function hints()
{
return [
return array_merge(parent::hints(), [
'ns' => 'This is the namespace of the ActiveRecord class to be generated, e.g., <code>app\models</code>',
'db' => 'This is the ID of the DB application component.',
'tableName' => 'This is the name of the DB table that the new ActiveRecord class is associated with, e.g. <code>tbl_post</code>.
......@@ -107,7 +109,7 @@ class Generator extends \yii\gii\Generator
you may want to uncheck this option to accelerate the code generation process.',
'generateLabelsFromComments' => 'This indicates whether the generator should generate attribute labels
by using the comments of the corresponding DB columns.',
];
]);
}
/**
......@@ -140,7 +142,7 @@ class Generator extends \yii\gii\Generator
*/
public function stickyAttributes()
{
return ['ns', 'db', 'baseClass', 'generateRelations', 'generateLabelsFromComments'];
return array_merge(parent::stickyAttributes(), ['ns', 'db', 'baseClass', 'generateRelations', 'generateLabelsFromComments']);
}
/**
......
......@@ -55,7 +55,7 @@ class <?= $className ?> extends <?= '\\' . ltrim($generator->baseClass, '\\') .
{
return [
<?php foreach ($labels as $name => $label): ?>
<?= "'$name' => '" . addslashes($label) . "',\n" ?>
<?= "'$name' => " . $generator->generateString($label) . ",\n" ?>
<?php endforeach; ?>
];
}
......
......@@ -12,3 +12,5 @@ echo $form->field($generator, 'baseClass');
echo $form->field($generator, 'db');
echo $form->field($generator, 'generateRelations')->checkbox();
echo $form->field($generator, 'generateLabelsFromComments')->checkbox();
echo $form->field($generator, 'enableI18N')->checkbox();
echo $form->field($generator, 'messageCategory');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment