Skip to content

Instantly share code, notes, and snippets.

@coryzibell
Created May 14, 2019 16:07
Show Gist options
  • Save coryzibell/7728ec6bfbff9451f38083ace3896671 to your computer and use it in GitHub Desktop.
Save coryzibell/7728ec6bfbff9451f38083ace3896671 to your computer and use it in GitHub Desktop.
Markdium-CraftCMS 3 - Modules and Plugins
Important to note that here we are using a fully qualified namespace to prevent conflicts with other plugins.
So, What Should I Use?
There are three questions that will influence whether or not you should build a plugin or a module:
Can your code be used on other projects? If so, build a plugin.
If the answer to this is yes, you should probably build a plugin. Creating a plugin means you can release it in the plugin store and benefit the community at large, or make money from it. Even if you only use the plugin for yourself or your organization, it's still valuable having portable functionality that can be used in multiple places.
Do you need "quick and dirty" functionality? If that's the case, a module is your best bet.
As much as we developers would love for everything to be properly planned and scoped, that often isn't the case, and sometimes you just need to add functionality to a site. If this is the case, it's probably best if you build a module. If you want the code to be portable later, you can always find time to turn it into a plugin 😂. Even though you need to add a bit of code to bootstrap the module, you don't need to create a separate repo, worry about installation across databases, etc.
Is the code integral and highly specific to your website/project? Probably best to build a module, then.
Many times we need to build code that communicates with custom APIs, works with unique business logic, or is just individually branded for a specific purpose. In this case, a module is your best bet. It will always be installed, and lives as part of your site's existing functionality and codebase, ensure they are tracked as a single project.
How Do I Get Started?
To get started, I recommend using the excellent https://pluginfactory.io/, created by nystudio107. It will bootstrap either a plugin or module for you, including all the controllers, services, variables, etc you might need.
If it's a plugin you created, you can test it by either specifying a local folder in composer.json, or pushing it up to a VCS repo, and then including it from there. And then once it's finished, publish it to the Craft Plugin Store and tweet @coryzibell and let me know what you built!
If you are making a module, make sure to follow the instructions in the README.md file on how to bootstrap the plugin and get composer to autoload it.
Not a developer, but need CraftCMS help? Reach out to us @digitalsurgeons and we'll see how we can help.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment