Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

About Acquia • Expert Drupal Support • Optimized Drupal hosting • Dev Cloud • Managed Cloud • Foster Drupal adoption • Commons • Dev Desktop • D8

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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 •

Slide 8

Slide 8 text

Routing D7 hook_menu D8 module.routing.yml module.menu_links.yml module.local_tasks.yml module.local_actions.yml

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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()

Slide 13

Slide 13 text

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!

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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)

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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/)

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Your turn Questions? @hernanibf @typhonius / @adammalone