From db9af448548d49df5eaf693c4f243ec821fc3c58 Mon Sep 17 00:00:00 2001 From: Elias Luhr Date: Tue, 26 Mar 2024 13:13:37 +0100 Subject: [PATCH] introduce enable or disable copy function --- src/commands/BatchController.php | 11 +++++++++-- src/generators/crud/Generator.php | 4 ++++ src/generators/crud/default/controller.php | 1 + src/generators/crud/default/views/view.php | 5 +++-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/commands/BatchController.php b/src/commands/BatchController.php index 305b299..cfc4d89 100644 --- a/src/commands/BatchController.php +++ b/src/commands/BatchController.php @@ -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 */ @@ -388,7 +393,8 @@ public function options($id) 'crudOverwriteRestControllerClass', 'crudOverwriteControllerClass', 'generateAccessFilterMigrations', - 'disablePluralization' + 'disablePluralization', + 'crudEnableCopy' ] ); } @@ -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; diff --git a/src/generators/crud/Generator.php b/src/generators/crud/Generator.php index 3166489..d11e22e 100644 --- a/src/generators/crud/Generator.php +++ b/src/generators/crud/Generator.php @@ -164,6 +164,8 @@ class Generator extends \yii\gii\generators\crud\Generator private $_p = []; public $translateRelations = ['translation', 'translation_meta']; + + public $enableCopy = true; /** * {@inheritdoc} @@ -237,6 +239,7 @@ public function rules() 'generateAccessFilterMigrations', 'singularEntities', 'modelMessageCategory', + 'enableCopy' ], 'safe', ], @@ -277,6 +280,7 @@ public function formAttributes() 'accessFilter', 'singularEntities', 'modelMessageCategory', + 'enableCopy' ]; } diff --git a/src/generators/crud/default/controller.php b/src/generators/crud/default/controller.php index 455af08..9b6a25a 100644 --- a/src/generators/crud/default/controller.php +++ b/src/generators/crud/default/controller.php @@ -67,6 +67,7 @@ class extends bas if ($traits) { echo "use {$traits};"; } + ?> accessFilter): ?> diff --git a/src/generators/crud/default/views/view.php b/src/generators/crud/default/views/view.php index ce07f6e..45737a0 100644 --- a/src/generators/crud/default/views/view.php +++ b/src/generators/crud/default/views/view.php @@ -43,7 +43,6 @@ * @var yii\web\View $this * @var modelClass, '\\') ?> $model */ -$copyParams = $model->hasMethod('getCopyParams') ? $model->getCopyParams() : $model->attributes; $this->title = Yii::t('modelMessageCategory ?>', ''); $this->params['breadcrumbs'][] = ['label' => Yii::t('modelMessageCategory ?>.plural', ''), 'url' => ['index']]; @@ -78,6 +77,7 @@ } ?> + enableCopy): ?> accessFilter) { echo 'getUser()->can(\'' . $permissions['update']['name'] . '\')): ?>'; @@ -85,7 +85,7 @@ ?> Html::a( ' ' . generateString('Copy ' . $modelName) ?>, - ['create', , 'modelClass) ?>'=>$copyParams], + ['create', , 'modelClass) ?>'=> $model->hasMethod('getCopyParams') ? $model->getCopyParams() : $model->attributes], ['class' => 'btn btn-success']) ?> '; } ?> + accessFilter) {