Drupal 8 Module Development
Not scary at all!
What we’ll cover
What's new? Why should I use D8?
What's new? Why should I use D8?
Better content authoring (Sidebar!)
What's new? Why should I use D8?
Drupal 7 is going away!
Drupal 6 - 13 February 2008
Drupal 7 - 5 January 2011
Drupal 8 - 19 November 2015
Drupal 9 - ????
Drupal 7 Example Module
Weather Widget Module - Block
Weather Widget Module - Configuration
Weather Widget Module - Page
Weather Widget Module - Github
Module code is on Github:
https://github.com/jaybeaton/tridug-d8-development-demo/tree/master/d7/tridug_weather
OK, but how do we do that in D8?
Let’s jump in!
Let’s jump in!
Let’s jump in!
Drupal 8 module diffs - yml files
Module .info files were replaced with .info.yml files.
Old:
New:
Drupal 8 module diffs - Routing
hook_menu() function replaced with .routing.yml and .links.menu.yml files.
Old:
New:
Drupal 8 module diffs - Forms
drupal_get_form() callback replaced with form classes.
Old:
New:
Configuration form
Drupal 8 module diffs - Blocks
hook_block_info() and hook_block_view() functions replaced with plugin classes.
Old:
New:
Weather Widget Block
Drupal 8 module diffs - Twig
PHPTemplate .tpl.php template files replaced with Twig templates.
Old:
New:
Drupal 8 module diffs - Controllers
hook_menu() functions with callbacks replaced with routes and controller classes.
Old:
New:
Drupal 8 module diffs - Entity data access
entity_metadata_wrapper calls replaced with entity classes.
Old:
New:
Drupal 8 module diffs - Database calls
Database calls replaced with… Well they’re kinda the same.
Old:
New:
Custom page
See, that wasn’t scary at all!
Drupal Console
It will write code for you!!!
Drupal Console - Generate Module Code
# drupal generate:module
Creates:
Module is here:
https://github.com/jaybeaton/tridug-d8-development-demo/tree/master/d8/tridug_weather_dc
Drupal Console - Generate Form Code
# drupal generate:form
Creates:
Drupal Console - Generate Block Code
# drupal generate:plugin:block
Creates:
Drupal Console - Generate Controller Code
# drupal generate:controller
Creates:
How to find help on D8?
Google!
Google!
Yes, but…
Search for “drupal 8 …” and limit the search to the last year.
Lots of help on Drupal Stack Exchange, too:
https://drupal.stackexchange.com/
Drupal API Documentation site
https://api.drupal.org/api/drupal
Start with a search for the Drupal 7 function that you’d use.
Often, there are comments saying what to use in D8.
Or, if it exists in D8, you can click on the D8 link.
Deprecated!
If the function is listed as “Deprecated”, it will show what to use instead.
That way, you’ll be ready for Drupal 9 with no changes!
Questions?
Go forth and build in D8!
Code is here: https://github.com/jaybeaton/tridug-d8-development-demo