Skip to content

Commit

Permalink
introduce enable or disable copy function
Browse files Browse the repository at this point in the history
  • Loading branch information
eluhr committed Mar 26, 2024
1 parent 53c7802 commit db9af44
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/commands/BatchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ class BatchController extends Controller

public $modelTranslationTableAdditions = ['name' => 'meta', 'fallbackLanguage' => false];

/**
* Whether the copy functionality for a crud should be created or not
*/
public $crudEnableCopy = true;

/**
* @var array application configuration for creating temporary applications
*/
Expand Down Expand Up @@ -388,7 +393,8 @@ public function options($id)
'crudOverwriteRestControllerClass',
'crudOverwriteControllerClass',
'generateAccessFilterMigrations',
'disablePluralization'
'disablePluralization',
'crudEnableCopy'
]
);
}
Expand Down Expand Up @@ -566,7 +572,8 @@ public function actionCruds()
'generateAccessFilterMigrations' => $this->generateAccessFilterMigrations,
'actionButtonColumnPosition' => $this->crudActionButtonColumnPosition,
'disablePluralization' => $this->disablePluralization,
'gridMaxColumns' => $this->crudGridMaxColumns
'gridMaxColumns' => $this->crudGridMaxColumns,
'enableCopy' => $this->crudEnableCopy
];
$route = 'gii/giiant-crud';
$app = \Yii::$app;
Expand Down
4 changes: 4 additions & 0 deletions src/generators/crud/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class Generator extends \yii\gii\generators\crud\Generator
private $_p = [];

public $translateRelations = ['translation', 'translation_meta'];

public $enableCopy = true;

/**
* {@inheritdoc}
Expand Down Expand Up @@ -237,6 +239,7 @@ public function rules()
'generateAccessFilterMigrations',
'singularEntities',
'modelMessageCategory',
'enableCopy'
],
'safe',
],
Expand Down Expand Up @@ -277,6 +280,7 @@ public function formAttributes()
'accessFilter',
'singularEntities',
'modelMessageCategory',
'enableCopy'
];
}

Expand Down
1 change: 1 addition & 0 deletions src/generators/crud/default/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class <?= $controllerClass ?> extends <?= StringHelper::basename($generator->bas
if ($traits) {
echo "use {$traits};";
}

?>

<?php if ($generator->accessFilter): ?>
Expand Down
5 changes: 3 additions & 2 deletions src/generators/crud/default/views/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
* @var yii\web\View $this
* @var <?= ltrim($generator->modelClass, '\\') ?> $model
*/
$copyParams = $model->hasMethod('getCopyParams') ? $model->getCopyParams() : $model->attributes;

$this->title = Yii::t('<?= $generator->modelMessageCategory ?>', '<?= $modelName ?>');
$this->params['breadcrumbs'][] = ['label' => Yii::t('<?= $generator->modelMessageCategory ?>.plural', '<?= $modelName ?>'), 'url' => ['index']];
Expand Down Expand Up @@ -78,21 +77,23 @@
}
?>

<?php if ($generator->enableCopy): ?>
<?php
if ($generator->accessFilter) {
echo '<?php if(\Yii::$app->getUser()->can(\'' . $permissions['update']['name'] . '\')): ?>';
}
?>
<?= '<?php ' . PHP_EOL . ' echo ' ?>Html::a(
'<span class="glyphicon glyphicon-copy"></span> ' . <?= $generator->generateString('Copy ' . $modelName) ?>,
['create', <?= $urlParams ?>, '<?= StringHelper::basename($generator->modelClass) ?>'=>$copyParams],
['create', <?= $urlParams ?>, '<?= StringHelper::basename($generator->modelClass) ?>'=> $model->hasMethod('getCopyParams') ? $model->getCopyParams() : $model->attributes],
['class' => 'btn btn-success'])
?>
<?php
if ($generator->accessFilter) {
echo '<?php endif ?>';
}
?>
<?php endif ?>

<?php
if ($generator->accessFilter) {
Expand Down

0 comments on commit db9af44

Please sign in to comment.