Craft & its Plugins | A transforming workflow

We like to think of Craft CMS as a Transformer (one with BumbleBee as his friend) and plugins as its Jet Pack. And every time we develop a plugin for Craft, it helps our Craft projects reach client’s expectations. Craft is a powerful CMS and its developers have left a lot of scope for extensibility. Plugins do the things that Craft CMS cannot. In our workflow Craft plugins help us do more than what Craft can do. Often our clients steer clear of plugin development because of the extra work and vulnerabilities it brings. That’s not the case with Craft plugins. You can read about plugin vulnerabilities in our Craft Vs WordPress blog. Before diving into our plugin development workflow you should know about Composer and Pluginfactory. Craft CMS 3 is highly dependent on the Composer for its development. Composer is a PHP package manager that helps Craft with PHP dependencies. Pluginfactory on the other hand is a different tool altogether it creates scaffolding for plugins. We use the scaffolding to configure our code in it. After defining the need we get on to the business of building the plugins. Craft documentation has a pretty straightforward approach to plugin development. Being big fans of Craft’s coding techniques we looked no further for inspiration. Our plugin development process is as simple as Craft’s.

Building “The Jet Pack” for Craft CMS

Image credit: pixabay

Nomenclature for the assembly

Like the parts of a Jet Pack, parts of the plugin should be named in a consistent format so that they can be identified easily. We follow the naming guidelines whether we’re naming packages or handles. It is safe and efficient to follow a particular nomenclature.

According to the Craft’s documentation-

  • Plugin handle must have lowercase letters, numbers, and dashes. All in Kebab case
  • Package name should have Craft- prefixed to it, after the ‘/’

Creating blueprint for “The Jet Pack”

Image credit: matej

Before we found out about pluginfactory, like every other developer we used to make our plugin structure manually. Pluginfactory creates a skeleton for your plugin in just a few clicks. It is created by a Craft developer named Andrew Welch. The scaffolding on pluginfactory are made using the Yeoman generator.

Details needed to create the scaffolding

  • API version
  • Plugin name
  • Description
  • Initial version
  • Plugin vendor
  • Plugin author
  • Author URL
  • Github name
When the structure is ready we feed our code into it and voila! Our plugin is ready.

Installing “The Jet Pack”

Image credit: jaguarmena

Plugins are written as composer packages. For Craft to recognize the plugin we have to install it as a composer dependency of the project. The installation depends on the nature of plugin whether it’s local or public. If it’s local we install it by configuring the composer.json and adding a new path repository record. The path must point toward the plugin’s root. If a plugin is made for a public release then it can also be installed directly via composer. After registering the plugin as a new composer package on Packagist, a require package command in composer fetches the package and installs it.

Final word: Plugins are essential

Image credit: jaguarmena

Plugins are not a crucial part of a CMS but it sure is important to achieve something out of the box based on client’s requirement. We find plugins to be extremely powerful and time-saving. The most important function of a plugin is to eliminate tedious and repetitive tasks by automating it. Some examples might put its importance into perspective.
  • SEO plugins make search engine optimization easier
  • E-commerce plugins improve customer journey.
  • Analytic plugins help with insights on page performance
  • Text and image editor plugins provide rich editing functionalities
If you’re looking to transform your Craft CMS experience — visual or performance — then plugins can help. As for the development of the plugin, talk to us here.