Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Designers Guide to Craft CMS Plugins

Jason Mayo
November 03, 2016

Designers Guide to Craft CMS Plugins

Jason Mayo

November 03, 2016

More Decks by Jason Mayo

Other Decks in Programming


  1. Controllers Used for passing data submitted from form’s to your

    services. Allow you to create, update& delete database tables, Allows you to input / output data from your front end templates e.g. {{ var }} Allows your plugin to be configurable by the user. Where all your functions and bulk of your plugin will go. Containers for the data so it can be passed between services etc. Settings Models Records Services Variables
  2. Adds, deletes & updates the events and entries to the

    database tables. Controllers Models Records Services Variables Points Allows admins to create & delete point events (e.g. Signed Up to Newsletter) and entries (e.g. Scott Signed Up to Newsletter) via a form in the Craft CMS Sets the data layout. E.g. 'Events’ have Event, Event Handle & Points. To be either stored via a record or manipulated via a service. All the logic for creating the events and entries is done inside functions in the services. Interacted by a Controller or Variable. e.g. {{ craft.points.addEntry({ eventHandle: 'SignedUpToNewsletter' }) }}
  3. Example Plugin Stores data in a custom table, and outputs

    selected rows with a variable. https://github.com/madebyshape/example-plugin
  4. Start with FieldTypes & Widgets If you want to create

    your rst plugin, these two types I found are the easiest way of getting started with plugins.
  5. Naming of core plugin les and functions Main les and

    functions start with the plugin name, then what the le type is... PluginName_WhatItDoesModel.php PluginName_WhatItDoesRecord.php PluginName_WhatItDoesController.php
  6. Debugging Similar to console.log() in jQuery, you can log messages

    in to your pluginname.log le in /craft/storage/logs/ * Reduces the hair loss when debugging ‘Array to string conversion’ issues PluginNamePlugin::log(’Mmm Donuts’);
  7. Using Craft CMS Form Fields In settings & eldtypes you

    can extend a form eld such as a elementSelect eld by knowing it’s name and attributes. {% import "_includes/forms" as forms %} {{ forms.textField({ label: 'New Code Group', name: 'codeGroup', }) }} /craft/app/templates/_includes/forms/
  8. http://craftcms.stackexchange.com/questions/ 6599/activerecord-de neattributes Knowing AttributeTypes When de ning models &

    records you need to state what ‘type’ it is, e.g. a Integer, Date etc. Knowing how to format these helps! 'eventDate' => array(AttributeType::DateTime)
  9. Use readily available settings Each plugin has it’s own ‘settings’

    column available in craft_plugins. If only using simple settings, avoid creating your own plugin settings table, and use this.
  10. 1. Create a shiny icon for your plugin* 2. Update

    the releases.json le 3. Create documentation * Very Important. Should be done before any coding starts tbh :)