Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions src/Scaffold/Console/CreatePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.'],
];
}
}
17 changes: 17 additions & 0 deletions src/Scaffold/Console/plugin/lang.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

return [
'plugin' => [
'name' => '{{name}}',
'description' => 'No description provided yet...'
],

'permissions' => [
'tab' => '{{name}}',
'label' => 'Some permission'
],

'navigation' => [
'label' => '{{name}}'
]
];
96 changes: 96 additions & 0 deletions src/Scaffold/Console/plugin/plugin-with-translations.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php namespace {{studly_author}}\{{studly_name}};

use Backend;
use System\Classes\PluginBase;

/**
* {{name}} Plugin Information File
*/
class Plugin extends PluginBase
{
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => '{{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,
],
];
}
}