├── codecov.yml ├── code-of-conduct.md ├── contributing.md ├── .styleci.yml ├── .editorconfig ├── src ├── LaravelCmsPluginServiceProvider.php ├── database │ └── migrations │ │ └── 2020_01_21_142800_update_plugin_settings_table.php ├── resources │ └── views │ │ └── plugins │ │ └── page-tab-myplugin001 │ │ └── myplugin001.blade.php └── Controllers │ └── MyPlugin001Controller.php ├── .php_cs ├── license.md ├── README.md └── composer.json /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | - Check the .php_cs 4 | -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | - Any open source product is only as good as the community behind it. You can participate by sharing code, ideas, or simply helping others. No matter what your skill level is, every contribution counts. 4 | -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | risky: false 3 | enabled: 4 | - alpha_ordered_imports 5 | - align_double_arrow 6 | - align_equals 7 | disabled: 8 | - length_ordered_imports 9 | - unused_use 10 | - unalign_equals 11 | finder: 12 | exclude: 13 | - modules 14 | - node_modules 15 | - storage 16 | - vendor 17 | name: "*.php" 18 | not-name: "*.blade.php" 19 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # For more information about the properties used in this file, 2 | # please see the EditorConfig documentation: 3 | # http://editorconfig.org 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | indent_size = 4 9 | indent_style = space 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | [*.{yml,js,json,css,scss,feature,eslintrc}] 14 | indent_size = 2 15 | indent_style = space 16 | 17 | [composer.json] 18 | indent_size = 4 -------------------------------------------------------------------------------- /src/LaravelCmsPluginServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([__DIR__.'/resources/views/plugins' => base_path('resources/views/vendor/laravel-cms/plugins')], 'myplugin001-views'); 16 | } 17 | 18 | /** 19 | * Register the application services. 20 | */ 21 | public function register() 22 | { 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | notPath('bootstrap/cache') 7 | ->notPath('storage') 8 | ->notPath('vendor') 9 | ->in(__DIR__) 10 | ->name('*.php') 11 | ->notName('*.blade.php') 12 | ->ignoreDotFiles(true) 13 | ->ignoreVCS(true) 14 | ; 15 | 16 | return PhpCsFixer\Config::create() 17 | ->setRules(array( 18 | '@Symfony' => true, 19 | 'binary_operator_spaces' => ['align_double_arrow' => true, 'align_equals' => true], 20 | 'array_syntax' => ['syntax' => 'short'], 21 | 'linebreak_after_opening_tag' => true, 22 | 'not_operator_with_successor_space' => true, 23 | 'ordered_imports' => true, 24 | 'phpdoc_order' => true, 25 | )) 26 | ->setFinder($finder) 27 | ; 28 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (C) 2019-2020 Alex Zeng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Semi-finished page-tab type EXAMPLE plugin 2 | 3 | - This is a semi-finished page-tab EXAMPLE plugin of Amila Laravel CMS 4 | - The main purpose of this example plugin is to guide you to make your own plugin easily 5 | - You can edit the blade template & Laravel controller to fit your own usage 6 | - Tutorial: https://www.laravelcms.tech/Laravel-Create-your-own-plugin.html 7 | 8 | ## Install it via the backend 9 | 10 | - Go to the CMS settings page -> Plugin -> search for myplugin001 11 | - Find alexstack/laravel-cms-plugin-myplugin001 12 | - Click the Install button 13 | 14 | ## What the plugin does for us? 15 | 16 | - An example of a page-tab plugin include blade and controller files 17 | 18 | ## Install it via command line manually 19 | 20 | ```php 21 | composer require alexstack/laravel-cms-plugin-myplugin001 22 | 23 | php artisan migrate --path=./vendor/alexstack/laravel-cms-plugin-myplugin001/src/database/migrations 24 | 25 | php artisan vendor:publish --force --tag=myplugin001-views 26 | 27 | php artisan laravelcms --action=clear 28 | 29 | ``` 30 | 31 | ## How to use it? 32 | 33 | - It's enabled after installing by default. You can see a MyPlugin tab when you edit a page. 34 | 35 | ## Improve this plugin & documents 36 | 37 | - You are very welcome to improve this plugin and how to use documents 38 | 39 | ## License 40 | 41 | - This Amila Laravel CMS plugin is open-source software licensed under the MIT license. 42 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alexstack/laravel-cms-plugin-myplugin001", 3 | "description": "This is a semi-finished page-tab EXAMPLE plugin, you can change the blade template & Laravel controller to fit your own usage.", 4 | "type": "amila-laravel-cms-plugin", 5 | "homepage": "https://github.com/AlexStack/Laravel-CMS-Plugin-MyPlugin001", 6 | "keywords": [ 7 | "laravel", 8 | "amila laravel cms", 9 | "example", 10 | "semi-finished", 11 | "amila laravel cms plugin" 12 | ], 13 | "license": "MIT", 14 | "support": { 15 | "issues": "https://github.com/AlexStack/Laravel-CMS-Plugin-MyPlugin001/issues" 16 | }, 17 | "authors": [{ 18 | "name": "Alex", 19 | "homepage": "https://github.com/AlexStack/Laravel-CMS-Plugin-MyPlugin001" 20 | }], 21 | "require": { 22 | "php": ">=7.0.0", 23 | "alexstack/laravel-cms": "*" 24 | }, 25 | "autoload": { 26 | "psr-4": { 27 | "Amila\\LaravelCms\\Plugins\\MyPlugin001\\": "src/" 28 | } 29 | }, 30 | "minimum-stability": "dev", 31 | "extra": { 32 | "laravel": { 33 | "providers": [ 34 | "Amila\\LaravelCms\\Plugins\\MyPlugin001\\LaravelCmsPluginServiceProvider" 35 | ] 36 | }, 37 | "laravel-cms": { 38 | "plugin-param-name": "page-tab-myplugin001" 39 | } 40 | }, 41 | "scripts": { 42 | "post-package-install": [ 43 | "php artisan migrate --path=./vendor/alexstack/laravel-cms-plugin-myplugin001/src/database/migrations/", 44 | "php artisan vendor:publish --provider=Amila\\LaravelCms\\Plugins\\MyPlugin001\\LaravelCmsPluginServiceProvider", 45 | "php artisan laravelcms --action=clear" 46 | ] 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/database/migrations/2020_01_21_142800_update_plugin_settings_table.php: -------------------------------------------------------------------------------- 1 | config = include base_path('config/laravel-cms.php'); 14 | $this->table_name = $this->config['table_name']['settings']; 15 | } 16 | 17 | /** 18 | * Run the migrations. 19 | */ 20 | public function up() 21 | { 22 | $setting_data = [ 23 | 'category' => 'plugin', 24 | 'param_name' => 'page-tab-myplugin001', 25 | 'input_attribute' => '{"rows":10,"required":"required"}', 26 | 'enabled' => 1, 27 | 'sort_value' => 20, 28 | 'abstract' => 'Semi-finished plugin for your own use. Add your Laravel controller into the CMS. Tutorial', 29 | 'param_value' => '{ 30 | "plugin_name": "My Plugin 001", 31 | "tab_name": "__(myplugin)", 32 | "real_update": "yes", 33 | "blade_template_dir": "your-laravel-project/resources/views/vendor/laravel-cms/plugins/page-tab-myplugin001", 34 | "php_controller_dir": "your-laravel-project/app/LaravelCms/Plugins/MyPlugin001", 35 | "blade_file": "myplugin001", 36 | "php_class": "App\\\\LaravelCms\\\\Plugins\\\\MyPlugin001\\\\Controllers\\\\MyPlugin001Controller" 37 | }', 38 | ]; 39 | LaravelCmsSetting::UpdateOrCreate( 40 | ['category'=>'plugin', 'param_name' => 'page-tab-myplugin001'], 41 | $setting_data 42 | ); 43 | } 44 | 45 | /** 46 | * Reverse the migrations. 47 | */ 48 | public function down() 49 | { 50 | LaravelCmsSetting::where('param_name', 'page-tab-myplugin001')->where('category', 'plugin')->delete(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/resources/views/plugins/page-tab-myplugin001/myplugin001.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{-- Display variable from the CMS settings --}} 4 |

{{ $helper->s("plugin.page-tab-myplugin001.plugin_name") }}

5 | 6 | {{-- Display variable from the plugin controller --}} 7 |
{{$plugins['myplugin001']['title']}}
8 | 9 |
This is a semi-finished plugin, you can change the blade template & Laravel 10 | controller to fit your own 11 | usage. 12 | Tutorial 14 |
15 | 16 | {{-- Display variable from the CMS settings --}} 17 | Blade Template Directory: {{ $helper->s("plugin.page-tab-myplugin001.blade_template_dir") }} 21 |
22 | PHP Controller Directory : {{ $helper->s("plugin.page-tab-myplugin001.php_controller_dir") }} 26 |
27 | 28 | @if ( $helper->s("plugin.page-tab-myplugin001.real_update") == 'yes')
29 | 33 |
34 | @endif 35 | 36 | {{-- Example of use multi-language label of a input --}} 37 |
38 | @include($helper->bladePath('includes.form-input','b'), ['name' => 39 | "extra_sub_content", 'type'=>'text', 'label'=>$helper->t('extra,sub_content')]) 40 |
41 | 42 | {{-- Display variable from the plugin controller --}} 43 |
44 | @include($helper->bladePath('includes.form-input','b'), ['name' => 45 | "translate_to_language", 'type'=>'select', 'options'=>$plugins['myplugin001']['languages']]) 46 |
47 | 48 |
49 | 50 | {{-- Example of use jQuery with a variable --}} 51 | 61 | -------------------------------------------------------------------------------- /src/Controllers/MyPlugin001Controller.php: -------------------------------------------------------------------------------- 1 | 'English', 'zh'=>'Chinese', 'es'=>'Spanish', 'ar'=>'Arabic', 'ja'=>'Japanese', 'hi'=>'Hindi', 'pt'=>'Portuguese', 'fr'=>'French', 'ru'=>'Russian', 'de'=>'German', 'ko'=>'Korean', 'it'=>'Italian', 'la'=>'Latin']; 19 | 20 | /** 21 | * No need to change it 22 | */ 23 | public function __construct() 24 | { 25 | $this->helper = new LaravelCmsHelper(); 26 | } 27 | 28 | /** 29 | * No need to change it 30 | */ 31 | public function checkUser() 32 | { 33 | if (! $this->user) { 34 | $this->user = $this->helper->hasPermission(); 35 | } 36 | } 37 | 38 | /** 39 | * Pass data to the plugin blade template which display the create new page form 40 | */ 41 | public function create($form_data, $page, $plugin_settings) 42 | { 43 | $data['title'] = 'You can define some variables in method create() in MyPlugin001Controller.php'; 44 | 45 | $data['backend_language'] = $this->helper->s('template.backend_language'); 46 | 47 | $data['languages'] = $this->langs; 48 | 49 | 50 | return $data; 51 | } 52 | 53 | /** 54 | * Pass data to the plugin blade template which display the edit page form 55 | */ 56 | public function edit($id, $page, $plugin_settings) 57 | { 58 | $data['title'] = 'You can define some variables in method edit() in MyPlugin001Controller.php'; 59 | 60 | $data['backend_language'] = $this->helper->s('template.backend_language'); 61 | 62 | $data['languages'] = $this->langs; 63 | 64 | 65 | return $data; 66 | } 67 | 68 | /** 69 | * Here we use the same update() method when add a new page 70 | */ 71 | public function store($form_data, $page, $plugin_settings) 72 | { 73 | return $this->update($form_data, $page, $plugin_settings); 74 | } 75 | 76 | /** 77 | * Below is an example for how to use $form_data, $page, $plugin_settings 78 | * And update the sub_content 79 | */ 80 | public function update($form_data, $page, $plugin_settings) 81 | { 82 | if ('' == trim($form_data['extra_sub_content'])) { 83 | return false; 84 | } 85 | if ('yes' == strtolower($plugin_settings['real_update'])) { 86 | $new_sub_content = $page->sub_content . $this->handleContent($form_data); 87 | 88 | // $this->helper->debug($form_data); 89 | 90 | $page->update(['sub_content' => $new_sub_content]); 91 | } 92 | } 93 | 94 | 95 | // public function destroy(Request $request, $id) 96 | // { 97 | // // 98 | // } 99 | 100 | 101 | /* 102 | * Other methods. 103 | */ 104 | public function handleContent($form_data) 105 | { 106 | return '
I want to translate below content to ' . $this->langs[$form_data['translate_to_language']] . '
' . $form_data['extra_sub_content'] . '

From MyPlugin001
You can change above text via edit the method handleContent() in the MyPlugin001Controller.php'; 107 | } 108 | } 109 | --------------------------------------------------------------------------------