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. Designers Guide To Craft CMS Plugins @madebyshape @madebymayo

  2. Shape

  3. None
  4. UI Designer Front End Developer

  5. Pro Googler UI Designer Front End Developer

  6. * https://github.com/madebyshape Select 2 Points Commerce Widgets Comments Rating Fyre

    Soon Tracking Private Code Redeem Private
  7. Where to start?

  8. None
  9. None
  10. None
  11. Write a spec

  12. 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
  13. FieldTypes Twig Extensions Widgets

  14. None
  15. 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' }) }}
  16. None
  17. Start to code

  18. Docs https://craftcms.com/docs/plugins/ Learn Yii https://larry.pub/index.php Mijingo https://mijingo.com/products/screencasts/craft-plugin-development/ Cocktail Recipes https://github.com/amacneil/cocktailrecipes

    Entry Count https://github.com/putyourlightson/craft-entry-count Craft CMS Slack
  19. “Backwards Engineer”

  20. Example Plugin Stores data in a custom table, and outputs

    selected rows with a variable. https://github.com/madebyshape/example-plugin
  21. Wish I Knew...

  22. 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.
  23. 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
  24. 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’);
  25. 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/
  26. 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)
  27. 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.
  28. Finishing Touches

  29. 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 :)
  30. Thanks @madebyshape @madebymayo