From cd73b997a1b84c472b0ea9240c546a434b85747e Mon Sep 17 00:00:00 2001 From: RomainMazB Date: Tue, 8 Jun 2021 23:16:11 +0200 Subject: [PATCH 1/4] Add --with-translations option to create:plugin command --- src/Scaffold/Console/CreatePlugin.php | 16 ++++ src/Scaffold/Console/plugin/lang.stub | 17 ++++ .../plugin/plugin-with-translations.stub | 96 +++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 src/Scaffold/Console/plugin/lang.stub create mode 100644 src/Scaffold/Console/plugin/plugin-with-translations.stub diff --git a/src/Scaffold/Console/CreatePlugin.php b/src/Scaffold/Console/CreatePlugin.php index 8c2821f4e..dada19f8a 100644 --- a/src/Scaffold/Console/CreatePlugin.php +++ b/src/Scaffold/Console/CreatePlugin.php @@ -37,6 +37,21 @@ class CreatePlugin extends GeneratorCommand 'plugin/version.stub' => 'updates/version.yaml', ]; + /** @inheritDoc */ + public function handle() + { + if ($this->hasOption('with-translations')) { + $currentLocale = config('app.locale'); + + $this->stubs['plugin/lang.stub'] = sprintf('lang/%s/lang.php', $currentLocale); + + unset($this->stubs['plugin/plugin.stub']); + $this->stubs['plugin/plugin-with-translations.stub'] = 'Plugin.php'; + } + + parent::handle(); + } + /** * Prepare variables for stubs. * @@ -87,6 +102,7 @@ protected function getOptions() { return [ ['force', null, InputOption::VALUE_NONE, 'Overwrite existing files with generated ones.'], + ['with-translations', null, InputOption::VALUE_NONE, 'Create lang folder and default locale file.'], ]; } } diff --git a/src/Scaffold/Console/plugin/lang.stub b/src/Scaffold/Console/plugin/lang.stub new file mode 100644 index 000000000..8b1e7e4c0 --- /dev/null +++ b/src/Scaffold/Console/plugin/lang.stub @@ -0,0 +1,17 @@ + [ + 'name' => '{{name}}', + 'description' => 'No description provided yet...' + ], + + 'permissions' => [ + 'tab' => '{{name}}', + 'label' => 'Some permission' + ], + + 'navigation' => [ + 'label' => '{{name}}' + ] +]; diff --git a/src/Scaffold/Console/plugin/plugin-with-translations.stub b/src/Scaffold/Console/plugin/plugin-with-translations.stub new file mode 100644 index 000000000..82da9637c --- /dev/null +++ b/src/Scaffold/Console/plugin/plugin-with-translations.stub @@ -0,0 +1,96 @@ + '{{lower_author}}.{{lower_name}}::lang.plugin.name', + 'description' => 'No description provided yet...', + 'author' => '{{author}}', + 'icon' => 'icon-leaf' + ]; + } + + /** + * Register method, called when the plugin is first registered. + * + * @return void + */ + public function register() + { + + } + + /** + * Boot method, called right before the request route. + * + * @return array + */ + public function boot() + { + + } + + /** + * Registers any front-end components implemented in this plugin. + * + * @return array + */ + public function registerComponents() + { + return []; // Remove this line to activate + + return [ + '{{studly_author}}\{{studly_name}}\Components\MyComponent' => 'myComponent', + ]; + } + + /** + * Registers any back-end permissions used by this plugin. + * + * @return array + */ + public function registerPermissions() + { + return []; // Remove this line to activate + + return [ + '{{lower_author}}.{{lower_name}}.some_permission' => [ + 'tab' => '{{lower_author}}.{{lower_name}}::lang.permissions.tab', + 'label' => '{{lower_author}}.{{lower_name}}::lang.permissions.label' + ], + ]; + } + + /** + * Registers back-end navigation items for this plugin. + * + * @return array + */ + public function registerNavigation() + { + return []; // Remove this line to activate + + return [ + '{{lower_name}}' => [ + 'label' => '{{lower_author}}.{{lower_name}}::lang.navigation.label', + 'url' => Backend::url('{{lower_author}}/{{lower_name}}/mycontroller'), + 'icon' => 'icon-leaf', + 'permissions' => ['{{lower_author}}.{{lower_name}}.*'], + 'order' => 500, + ], + ]; + } +} From c7e5b2cb32c28a69b9c5ec2ad078876b5f916c36 Mon Sep 17 00:00:00 2001 From: RomainMazB Date: Tue, 8 Jun 2021 23:22:52 +0200 Subject: [PATCH 2/4] Add missing plugin description key --- src/Scaffold/Console/plugin/plugin-with-translations.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Scaffold/Console/plugin/plugin-with-translations.stub b/src/Scaffold/Console/plugin/plugin-with-translations.stub index 82da9637c..00b469816 100644 --- a/src/Scaffold/Console/plugin/plugin-with-translations.stub +++ b/src/Scaffold/Console/plugin/plugin-with-translations.stub @@ -17,7 +17,7 @@ class Plugin extends PluginBase { return [ 'name' => '{{lower_author}}.{{lower_name}}::lang.plugin.name', - 'description' => 'No description provided yet...', + 'description' => '{{lower_author}}.{{lower_name}}::lang.plugin.description', 'author' => '{{author}}', 'icon' => 'icon-leaf' ]; From e04135c61d380153f5b181234a740e9711a193ee Mon Sep 17 00:00:00 2001 From: RomainMazB Date: Wed, 9 Jun 2021 00:01:02 +0200 Subject: [PATCH 3/4] Move $stubs declaration into handle instead of unset keys --- src/Scaffold/Console/CreatePlugin.php | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Scaffold/Console/CreatePlugin.php b/src/Scaffold/Console/CreatePlugin.php index dada19f8a..869d69f99 100644 --- a/src/Scaffold/Console/CreatePlugin.php +++ b/src/Scaffold/Console/CreatePlugin.php @@ -27,26 +27,22 @@ class CreatePlugin extends GeneratorCommand */ protected $type = 'Plugin'; - /** - * A mapping of stub to generated file. - * - * @var array - */ - protected $stubs = [ - 'plugin/plugin.stub' => 'Plugin.php', - 'plugin/version.stub' => 'updates/version.yaml', - ]; - /** @inheritDoc */ public function handle() { if ($this->hasOption('with-translations')) { $currentLocale = config('app.locale'); - $this->stubs['plugin/lang.stub'] = sprintf('lang/%s/lang.php', $currentLocale); - - unset($this->stubs['plugin/plugin.stub']); - $this->stubs['plugin/plugin-with-translations.stub'] = 'Plugin.php'; + $this->stubs = [ + 'plugin/lang.stub' => sprintf('lang/%s/lang.php', $currentLocale), + 'plugin/plugin-with-translations.stub' => 'Plugin.php', + 'plugin/version.stub' => 'updates/version.yaml' + ]; + } else { + $this->stubs = [ + 'plugin/plugin.stub' => 'Plugin.php', + 'plugin/version.stub' => 'updates/version.yaml', + ]; } parent::handle(); From 438b171758bf82b4ff6b6405fe46e75c28508ee9 Mon Sep 17 00:00:00 2001 From: RomainMazB Date: Wed, 9 Jun 2021 00:25:27 +0200 Subject: [PATCH 4/4] Fix $this->hasOption > $this->option --- src/Scaffold/Console/CreatePlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Scaffold/Console/CreatePlugin.php b/src/Scaffold/Console/CreatePlugin.php index 869d69f99..a89fb49a4 100644 --- a/src/Scaffold/Console/CreatePlugin.php +++ b/src/Scaffold/Console/CreatePlugin.php @@ -30,7 +30,7 @@ class CreatePlugin extends GeneratorCommand /** @inheritDoc */ public function handle() { - if ($this->hasOption('with-translations')) { + if ($this->option('with-translations')) { $currentLocale = config('app.locale'); $this->stubs = [