├── .gitignore ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json ├── config └── app.php └── modules └── sitemodule ├── .craftplugin ├── .gitignore ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── config └── app.php └── src ├── SiteModule.php ├── assetbundles └── sitemodule │ ├── SiteModuleAsset.php │ └── dist │ ├── css │ └── SiteModule.css │ ├── img │ └── SiteModule-icon.svg │ └── js │ └── SiteModule.js └── translations └── en └── site-module.php /.gitignore: -------------------------------------------------------------------------------- 1 | # Craft 3 .gitignore 2 | # 3 | # Example .gitignore file for Craft 3 CMS projects 4 | # 5 | # @author nystudio107 6 | # @copyright Copyright (c) 2017 nystudio107 7 | # @link https://nystudio107.com/ 8 | # @package nystudio107/craft 9 | # @since 1.0.0 10 | # @license MIT 11 | 12 | # This file should be renamed to '.gitignore' and placed in your 13 | # Craft 3 CMS project root directory 14 | 15 | # CRAFT ENVIRONMENT 16 | .env.php 17 | .env.sh 18 | .env 19 | 20 | # COMPOSER 21 | /vendor 22 | 23 | # CRAFT STORAGE 24 | /storage/* 25 | !/storage/.gitkeep 26 | 27 | # ASSETS 28 | /web/assets/* 29 | 30 | # BUILD FILES 31 | /bower_components/* 32 | /node_modules/* 33 | /build/* 34 | /yarn-error.log 35 | /npm-debug.log 36 | 37 | # TRANSCODER 38 | /web/transcoder/* 39 | 40 | # MISC FILES 41 | .cache 42 | .DS_Store 43 | .idea 44 | .project 45 | .settings 46 | *.esproj 47 | *.sublime-workspace 48 | *.sublime-project 49 | *.tmproj 50 | *.tmproject 51 | .vscode/* 52 | !.vscode/settings.json 53 | !.vscode/tasks.json 54 | !.vscode/launch.json 55 | !.vscode/extensions.json 56 | config.codekit3 57 | prepros-6.config 58 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # nystudio107/site-module Change Log 2 | 3 | ## 1.0.2 - 2018.05.22 4 | ### Changed 5 | * Fixed controller namespacing 6 | 7 | ## 1.0.1 - 2018.01.18 8 | ### Added 9 | * Synced with pluginfactory.io generated modules 10 | 11 | ## 1.0.0 - 2017.12.30 12 | ### Added 13 | * Initial release 14 | 15 | Brought to you by [nystudio107](https://nystudio107.com/) 16 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) nystudio107. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # site-module for Craft CMS 3.x 2 | 3 | An example module for Craft CMS 3 that lets you enhance your websites with a custom site module. 4 | 5 | ## Requirements 6 | 7 | This module requires Craft CMS 3.0.0-RC3 or later. 8 | 9 | ## Installation 10 | 11 | To install the plugin, follow these instructions. 12 | 13 | 1. Copy the `modules` folder into your project root directory 14 | 15 | 2. Either copy the `app.php` into your `config/` directory, or copy & paste the `*` settings in the `app.php` into your project's `app.php` file 16 | 17 | 3. Make sure you have the following in your project's `composer.json`: 18 | ``` 19 | "autoload": { 20 | "psr-4": { 21 | "modules\\sitemodule\\": "modules/sitemodule/src/" 22 | } 23 | }, 24 | ``` 25 | 26 | 4. If you didn't have the above `autoload` settings in your `composer.json` you'll also need to do the following command from your project root: 27 | ``` 28 | composer dump-autoload 29 | ``` 30 | 31 | ## site-module Overview 32 | 33 | Read the [Enhancing a Craft CMS 3 Website with a Custom Module](https://nystudio107.com/blog/enhancing-a-craft-cms-3-website-with-a-custom-module) article for details. 34 | 35 | ## site-module Roadmap 36 | 37 | Some things to do, and ideas for potential features: 38 | 39 | * Initial release 40 | 41 | Brought to you by [nystudio107](https://nystudio107.com/) 42 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nystudio107/site-module", 3 | "description": "An example module for Craft CMS 3 that lets you enhance your websites with a custom site module", 4 | "version": "1.0.2", 5 | "keywords": [ 6 | "craft", 7 | "cms", 8 | "craftcms", 9 | "site", 10 | "module", 11 | "site-module" 12 | ], 13 | "license": "MIT", 14 | "homepage": "https://nystudio107.com/", 15 | "type": "project", 16 | "support": { 17 | "email": "info@nystudio107.com", 18 | "issues": "https://github.com/nystudio107/site-module/issues", 19 | "source": "https://github.com/nystudio107/site-module", 20 | "docs": "https://github.com/nystudio107/site-module" 21 | }, 22 | "minimum-stability": "dev", 23 | "prefer-stable": true, 24 | "require": { 25 | "php": ">=7.0.0" 26 | }, 27 | "autoload": { 28 | "psr-4": { 29 | "modules\\sitemodule\\": "modules/sitemodule/src/" 30 | } 31 | }, 32 | "config": { 33 | "optimize-autoloader": true 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /config/app.php: -------------------------------------------------------------------------------- 1 | [ 20 | 'modules' => [ 21 | 'site-module' => [ 22 | 'class' => \modules\sitemodule\SiteModule::class, 23 | ], 24 | ], 25 | 'bootstrap' => ['site-module'], 26 | ], 27 | 28 | // Live (production) environment 29 | 'live' => [ 30 | ], 31 | 32 | // Staging (pre-production) environment 33 | 'staging' => [ 34 | ], 35 | 36 | // Local (development) environment 37 | 'local' => [ 38 | ], 39 | ]; 40 | -------------------------------------------------------------------------------- /modules/sitemodule/.craftplugin: -------------------------------------------------------------------------------- 1 | {"pluginName":"Site","pluginDescription":"An example module for Craft CMS 3 that lets you enhance your websites with a custom site module","pluginVersion":"1.0.0","pluginAuthorName":"nystudio107","pluginVendorName":"nystudio107","pluginAuthorUrl":"https://nystudio107.com/","codeComments":[],"pluginComponents":[],"apiVersion":"module_api_version_3_0"} -------------------------------------------------------------------------------- /modules/sitemodule/.gitignore: -------------------------------------------------------------------------------- 1 | # CRAFT ENVIRONMENT 2 | .env.php 3 | .env.sh 4 | .env 5 | 6 | # COMPOSER 7 | /vendor 8 | 9 | # BUILD FILES 10 | /bower_components/* 11 | /node_modules/* 12 | /build/* 13 | /yarn-error.log 14 | 15 | # MISC FILES 16 | .cache 17 | .DS_Store 18 | .idea 19 | .project 20 | .settings 21 | *.esproj 22 | *.sublime-workspace 23 | *.sublime-project 24 | *.tmproj 25 | *.tmproject 26 | .vscode/* 27 | !.vscode/settings.json 28 | !.vscode/tasks.json 29 | !.vscode/launch.json 30 | !.vscode/extensions.json 31 | config.codekit3 32 | prepros-6.config 33 | -------------------------------------------------------------------------------- /modules/sitemodule/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Site Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). 6 | 7 | ## 1.0.0 - 2018-01-19 8 | ### Added 9 | - Initial release 10 | -------------------------------------------------------------------------------- /modules/sitemodule/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 nystudio107 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. -------------------------------------------------------------------------------- /modules/sitemodule/README.md: -------------------------------------------------------------------------------- 1 | # Site module for Craft CMS 3.x 2 | 3 | An example module for Craft CMS 3 that lets you enhance your websites with a custom site module 4 | 5 | ## Requirements 6 | 7 | This module requires Craft CMS 3.0.0-RC1 or later. 8 | 9 | ## Installation 10 | 11 | To install the module, follow these instructions. 12 | 13 | First, you'll need to add the contents of the `app.php` file to your `config/app.php` (or just copy it there if it does not exist). This ensures that your module will get loaded for each request. The file might look something like this: 14 | ``` 15 | return [ 16 | 'modules' => [ 17 | 'site-module' => [ 18 | 'class' => \modules\sitemodule\SiteModule::class, 19 | ], 20 | ], 21 | 'bootstrap' => ['site-module'], 22 | ]; 23 | ``` 24 | You'll also need to make sure that you add the following to your project's `composer.json` file so that Composer can find your module: 25 | 26 | "autoload": { 27 | "psr-4": { 28 | "modules\\sitemodule\\": "modules/sitemodule/src/" 29 | } 30 | }, 31 | 32 | After you have added this, you will need to do: 33 | 34 | composer dump-autoload 35 | 36 | …from the project’s root directory, to rebuild the Composer autoload map. This will happen automatically any time you do a `composer install` or `composer update` as well. 37 | 38 | ## Site Overview 39 | 40 | -Insert text here- 41 | 42 | ## Using Site 43 | 44 | -Insert text here- 45 | 46 | ## Site Roadmap 47 | 48 | Some things to do, and ideas for potential features: 49 | 50 | * Release it 51 | 52 | Brought to you by [nystudio107](https://nystudio107.com/) 53 | -------------------------------------------------------------------------------- /modules/sitemodule/config/app.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'site-module' => [ 18 | 'class' => \modules\sitemodule\SiteModule::class, 19 | ], 20 | ], 21 | 'bootstrap' => ['site-module'], 22 | ]; 23 | -------------------------------------------------------------------------------- /modules/sitemodule/src/SiteModule.php: -------------------------------------------------------------------------------- 1 | getBasePath()); 52 | $this->controllerNamespace = 'modules\sitemodule\controllers'; 53 | 54 | // Translation category 55 | $i18n = Craft::$app->getI18n(); 56 | /** @noinspection UnSafeIsSetOverArrayInspection */ 57 | if (!isset($i18n->translations[$id]) && !isset($i18n->translations[$id.'*'])) { 58 | $i18n->translations[$id] = [ 59 | 'class' => PhpMessageSource::class, 60 | 'sourceLanguage' => 'en-US', 61 | 'basePath' => '@modules/sitemodule/translations', 62 | 'forceTranslation' => true, 63 | 'allowOverrides' => true, 64 | ]; 65 | } 66 | 67 | // Base template directory 68 | Event::on(View::class, View::EVENT_REGISTER_CP_TEMPLATE_ROOTS, function (RegisterTemplateRootsEvent $e) { 69 | if (is_dir($baseDir = $this->getBasePath().DIRECTORY_SEPARATOR.'templates')) { 70 | $e->roots[$this->id] = $baseDir; 71 | } 72 | }); 73 | 74 | // Set this as the global instance of this module class 75 | static::setInstance($this); 76 | 77 | parent::__construct($id, $parent, $config); 78 | } 79 | 80 | /** 81 | * @inheritdoc 82 | */ 83 | public function init() 84 | { 85 | parent::init(); 86 | self::$instance = $this; 87 | 88 | if (Craft::$app->getRequest()->getIsCpRequest()) { 89 | Event::on( 90 | View::class, 91 | View::EVENT_BEFORE_RENDER_TEMPLATE, 92 | function (TemplateEvent $event) { 93 | try { 94 | Craft::$app->getView()->registerAssetBundle(SiteModuleAsset::class); 95 | } catch (InvalidConfigException $e) { 96 | Craft::error( 97 | 'Error registering AssetBundle - '.$e->getMessage(), 98 | __METHOD__ 99 | ); 100 | } 101 | } 102 | ); 103 | } 104 | 105 | Craft::info( 106 | Craft::t( 107 | 'site-module', 108 | '{name} module loaded', 109 | ['name' => 'Site'] 110 | ), 111 | __METHOD__ 112 | ); 113 | } 114 | 115 | // Protected Methods 116 | // ========================================================================= 117 | } 118 | -------------------------------------------------------------------------------- /modules/sitemodule/src/assetbundles/sitemodule/SiteModuleAsset.php: -------------------------------------------------------------------------------- 1 | sourcePath = "@modules/sitemodule/assetbundles/sitemodule/dist"; 33 | 34 | $this->depends = [ 35 | CpAsset::class, 36 | ]; 37 | 38 | $this->js = [ 39 | 'js/SiteModule.js', 40 | ]; 41 | 42 | $this->css = [ 43 | 'css/SiteModule.css', 44 | ]; 45 | 46 | parent::init(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /modules/sitemodule/src/assetbundles/sitemodule/dist/css/SiteModule.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Site module for Craft CMS 3 | * 4 | * Site CSS 5 | * 6 | * @author nystudio107 7 | * @copyright Copyright (c) 2018 nystudio107 8 | * @link https://nystudio107.com/ 9 | * @package SiteModule 10 | * @since 1.0.0 11 | */ 12 | -------------------------------------------------------------------------------- /modules/sitemodule/src/assetbundles/sitemodule/dist/img/SiteModule-icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 14 | 17 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /modules/sitemodule/src/assetbundles/sitemodule/dist/js/SiteModule.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Site module for Craft CMS 3 | * 4 | * Site JS 5 | * 6 | * @author nystudio107 7 | * @copyright Copyright (c) 2018 nystudio107 8 | * @link https://nystudio107.com/ 9 | * @package SiteModule 10 | * @since 1.0.0 11 | */ 12 | -------------------------------------------------------------------------------- /modules/sitemodule/src/translations/en/site-module.php: -------------------------------------------------------------------------------- 1 | 'Site plugin loaded', 18 | ]; 19 | --------------------------------------------------------------------------------