diff --git a/src/Scaffold/Console/CreatePlugin.php b/src/Scaffold/Console/CreatePlugin.php index 8c2821f4e..a89fb49a4 100644 --- a/src/Scaffold/Console/CreatePlugin.php +++ b/src/Scaffold/Console/CreatePlugin.php @@ -27,15 +27,26 @@ 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->option('with-translations')) { + $currentLocale = config('app.locale'); + + $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(); + } /** * Prepare variables for stubs. @@ -87,6 +98,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..00b469816 --- /dev/null +++ b/src/Scaffold/Console/plugin/plugin-with-translations.stub @@ -0,0 +1,96 @@ + '{{lower_author}}.{{lower_name}}::lang.plugin.name', + 'description' => '{{lower_author}}.{{lower_name}}::lang.plugin.description', + '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, + ], + ]; + } +}