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

Drupal 8 Hackathon Primer

Drupal 8 Hackathon Primer

I quick overview of Drupal 8 changes and how to start porting modules.

typhonius

June 18, 2014
Tweet

More Decks by typhonius

Other Decks in Technology

Transcript

  1. About Acquia • Expert Drupal Support • Optimized Drupal hosting

    • Dev Cloud • Managed Cloud • Foster Drupal adoption • Commons • Dev Desktop • D8
  2. About us Adam Malone (typhonius) • Technical Consultant (APAC) •

    Born in .co.uk • Lives in .com.au • Drupalist since ‘11 • Contributor since ‘12 • Acquian since ‘13 Hernâni Borges de Freitas (hernani) • Technical Team Lead (EMEA) • .PT • Lives in .UK • Long time PHP Developer • Drupalist since 2008 • Acquian since 2011
  3. Why port modules? • Give yourself a headstart • Provide

    support for D8 in contrib on release date (D8CX) • Learn the APIs for custom modules • Stepping stone to learning Core • Stepping stone to learning Symfony, Guzzle, phpunit, twig etc
  4. Recommended Tools • Acquia Dev Desktop (Beta2) • Configured for

    PHP 5.4+ • Already with Drush 7 • A proper IDE • Eclipse • Netbeans • PHPStorm • Drupal Essential • Devel module (http://drupal.org/project/devel) (enable devel and kint) • Drupal optional • Module Upgrader project • Skeleton scripts • Module upgrade scripts
  5. Important requirement - choose a module • Remember you have

    only 12 hours of work ahead • Remember you will hit blockers • Review module’s issue queue to verify there isn’t any work already developed for d8 • Start small • find a simple module • select modules you’ve used • Try not to pick a module that will use entities as a first module • Review your choice before going ahead
  6. Suggested Steps • Break the module in parts (routing/config/forms/callbacks) •

    Create .info.yml and associated .module file • If needed create .install file with associated schemas • Install module verify if it appeared installed and if needed the schemas were created in DB • Port old hook_menu to new routing • Copy over associated hook_permission if needed • Convert admin forms • Port other defined hooks • Convert old tpl.php functions to new twig templates • Assign different parts of the build to different people • One person does config • One person does routing • One builds forms and controllers •
  7. Entities D7 • $node->field_foo [LANGUAGE_NONE][0] [‘value’] • node • user

    • file D8 • $node->title->value; • $node->field_foo->value • content • node • user etc • config • image style • view etc
  8. Configuration management D7 - variable_get, variable_set - Modules defining their

    own ctools exportable like content types or views - Features exporting configuration Mix between files and db D8 • $config->get(‘variable’) • Configuration entities could be part of module config • Exportable • defaults => yaml • active => db • staging => files can be imported into active
  9. Configuration management user.flood.yml user.mail.yml user.role.anonymous.yml user.role.authenticated.yml user.settings.yml $conf = \Drupal::config('user.flood');

    uid_only: false ip_limit: 50 ip_window: 3600 user_limit: 5 user_window: 21600 $conf->get(‘user_limit’); 5 $conf->set(‘user_limit’, 1); $conf->save(); D8 examples
  10. Others D7 • Blocks defined in hooks • Global variables

    $user • Functions like l(), t() • Drush cc all • dpm() D8 • Blocks defined in their own plugin defined by an annotated class. • Objects and functions accessible by service controllers. • Drush cr • ksm()
  11. Blockers • Function not defined Look in change records to

    commits involving the function to understand what is the equivalent one in D8. https://drupal.org/list-changes/drupal Same method can be applied to other similar symptoms like hook not being called or code not being executed. Verify code defining the function is loaded. • Look for inspiration in examples module, in core or in api.drupal.org • Always check logs (Drupal and PHP). • Check with your team before any task to get a common understanding of effort. • Ask for help, we are here for that!
  12. Other tips • For contrib work, use the latest release

    (alpha/beta/rc) • Assume HEAD will break your code • IDEs can help you with deprecations • Change notices are usually great to peruse • Don’t be afraid to look at how core/another module does something, it’s not cheating
  13. Debugging • Read the error message! :) • debug($var, '',

    TRUE); • If WSOD, tail your PHP error log. ◦ tail -f /path/to/php_error.log • Comment out hook_install()/hook_uninstall(). • Run rebuild.php. (new!) ◦ settings.php: $settings['rebuild_access'] = TRUE; ◦ http://myd8site/rebuild.php or drush rebuild • Clear the cache. ◦ drush cr # need "master" branch from github • Uninstall/reinstall your module. • Reinstall your site. (no 8.x->8.x upgrades yet)
  14. Suggested modules • Masquerade • Metatag • Realname • Chosen

    • Comment RSS • List predefined options • Realname • Menu Attributes • Role Activity Your own module ? • Token formatters • Aggregator item length • Filter protocols • Flood control • r4032login • password policy
  15. Homework • Look to pants module • https://drupal.org/project/pants • Look

    to examples module • https://drupal.org/project/examples • Look through some already ported modules Other examples • Views in core • Rules (http://d8rules.org/)
  16. Resources • Drupal 8 Module Upgrade Lab presentation: https://docs.google. com/a/acquia.

    com/presentation/d/1I1t1y_m3Gfq0nVngJN33XB0D49l8RcyzdIaF2 0Li3M8/edit#slide=id.p • Drupal 8 in a nutshell https://austin2014.drupal.org/session/drupal-8-nutshell • Drupal 8 where did the code go http://www.nyccamp.org/sites/default/files/slides/pwolanin-2014-04- Drupal-8-code-go.pdf • Drupal 8 API overview documentation: https://drupal. org/developing/api/8