rapid module development
play

Rapid Module Development Drupaldelphia, April 27, 2018 Intros Tom - PowerPoint PPT Presentation

Rapid Module Development Drupaldelphia, April 27, 2018 Intros Tom Mount Eastern Standard Technology Lead, Eastern Standard Philadelphia-based marketing and Closet geek technology agency Hobbies include bass guitar and


  1. Rapid Module Development Drupaldelphia, April 27, 2018

  2. Intros Tom Mount Eastern Standard ● Technology Lead, Eastern Standard ● Philadelphia-based marketing and Closet geek technology agency ● ● Hobbies include bass guitar and rec ● Collaborative dev team football year-round We’re hiring! ● ● Email: tomm@easternstandard.com Drupal: https://www.drupal.org/u/tmountjr ●

  3. Cliche alert: “Work smarter, not harder.”

  4. The Not-So-Rapid Setup

  5. Tools: What you probably already have ● A CLI/terminal/command prompt ● A Drupal 8 project, one that’s either set up somewhere already, or at least the zipped version of Drupal Core 8.5.72.

  6. Tools: What you should download ● VSCode (https://code.visualstudio.com/), available for Windows, OS X, and Linux (.rpm and .deb), along with some plugins: PHP Debug (https://github.com/felixfbecker/vscode-php-debug) ● ● EditorConfig (https://github.com/editorconfig/editorconfig-vscode) PHP DocBlocker (https://github.com/neild3r/vscode-php-docblocker) ● ● PHP CS (https://github.com/ikappas/vscode-phpcs) PHP CS Fixer (https://github.com/junstyle/vscode-php-cs-fixer) ● ● Drupal Console (https://drupalconsole.com/) ● Docker (https://www.docker.com/) ● Lando (https://docs.devwithlando.io/) Note that the only plugin we’ll definitely be using here is PHP Debug . The others are nice to have and help you write beautiful and standards-compliant code quickly, but it probably won’t speed up your actual code writing.

  7. Tools: What you might need to download, but probably not. Chances are good you already have these installed and running. But in case you don’t: ● Git ● Composer ● Drush (https://www.drush.org/) ● Drush 8 may already be installed globally (http://docs.drush.org/en/8.x/install/) ● Drush 9 may already be installed in the project and can be accessed with Drush Launcher (https://github.com/drush-ops/drush-launcher)

  8. Tools: The One-Time Setup To follow along, you’ll need to do the following: ● Install VSCode and all the extensions. ● Install Docker. ● Install Lando. ● Install Drupal Console Launcher.

  9. Now can we get to developing? (It’s been like two hours already!)

  10. Your Module: What will it do? Having a clear idea of what you want to accomplish with your custom module will save you time later. The Drupal module ecosystem is pretty big; maybe someone has already done what you want to do? Spending 30 minutes poking around https://drupal.org is definitely faster than spending six hours writing a custom module that someone else has already written. Efficiency isn’t necessarily about doing things quickly, it’s about being smart in your approach.

  11. Your Module: What will it do? Let’s create a very custom module: ● Should store its configuration the way other modules store Drupal configuration. ● Should include a form to edit those config values. ● Should include a menu link to that form. ● Should include some level of permission control that site owners can set if they so desire. In most cases, your custom module will have a lot more functionality, but this is fine for the purposes of a demo.

  12. Step 0: Set up a new/existing local Drupal site.

  13. Set up a new/existing local Drupal site

  14. Set up a new/existing local Drupal site

  15. Step 1: Create your module.

  16. Create your module

  17. (Optional) Step 1.5: Move the module.

  18. Move the module

  19. Step 2: Enable the module.

  20. Enable the module

  21. Step 3: Generate a config file and form.

  22. Generate a config file and form

  23. Generate a config file and form

  24. Step 4: Verify config is being saved.

  25. Verify config is being saved

  26. The end! …?

  27. Where to go from here We could stop here. We have a config form, and several hundred lines of code that we didn’t have to write that handle routing, configuration, and menus. But the form asks for an API URL. And it happily accepts “hello world.” Let’s fix that.

  28. Step 5: Add validation.

  29. Validation, part 1: making sure XDebug works XDebug is a fantastic PHP debugger. You can step through your code line by line, jump in and out of methods, get detailed stack traces, set conditional breakpoints...everything you need to inspect what’s happening in your module under the surface. It’s fairly easy to set up in VSCode.

  30. Validation, part 1: making sure XDebug works

  31. Validation, part 1: making sure XDebug works

  32. Validation, part 1: making sure XDebug works

  33. Validation, part 1: making sure XDebug works

  34. Validation, part 2: figuring out how to validate Back in the day, everyone had their own regular expression for URLs, email addresses, etc. They all had problems. Luckily, a quick Google search (“drupal 8 valid url”) landed me on the UrlHelper::isValid() documentation page. The method looks easy enough to figure out how it works, but let’s test it anyway with another great tool: the Drupal PHP REPL.

  35. Validation, part 2: figuring out how to validate

  36. Validation, part 3: actually validating

  37. Validation, part 3: actually validating

  38. Step 6: Add permissions.

  39. Add permissions

  40. Add permissions

  41. Add permissions

  42. Add permissions

  43. Test permissions

  44. Test permissions

  45. Test permissions

  46. Test permissions

  47. Recap

  48. How is this faster? Instead of… ...we can… ...setting up on Pantheon or Acquia, committing code, ...use Lando as a local development environment. testing, committing more code, doing more testing...

  49. How is this faster? Instead of… ...we can… ...reading the Form API and menu docs and writing a few ...use the Drupal Console to generate a brand new hundred lines of code by hand, then reading a bunch of module, set up a new config file, create a configuration blogs about how to set up new configuration files and editing form, and set up permissions. writing a few dozen more lines of code by hand...

  50. How is this faster? Instead of… ...we can… ...clicking around in the admin interface for a while to ...use the Drupal Console to stub out a new user role and create roles and a new user... a new user, right from the command line.

  51. How is this faster? Instead of… ...we can… ...choosing a password, writing it down or putting it in a ...use Drush and a private browsing window to log in as password manager, and cluttering up your brain... that new user without worrying what the password was.

  52. How is this faster? Instead of… ...we can… ...dropping a bunch of var_dump(); die(); ...use a free and powerful IDE, along with a proper statements everywhere, or, if you want to get really debugging tool, to quickly inspect variables while our elegant, installing the debug module and using kint() code was running, letting us get some insight into Drupal everywhere, both of which require reloading the page was doing “under the hood.” every time you change anything… (What you’re looking for wasn’t in the variable you kint() ed? Guess you gotta reload and try again!)

  53. How is this faster? Instead of… ...we can… ...doing something silly like making a custom route that ...use Drush’s PHP REPL to quickly test out some inputs exists solely to run one statement and print the output to against a Drupal utility method without having to guess or the screen (which I’ve done) or blindly hammering away go the long way around. at a method until you find the right variable to pass...

  54. Further Reading

  55. Further Reading ● XDebug: https://deliciousbrains.com/xdebug-advanced-php-debugging/ ● Docksal, similar to Lando, might be easier if you already know Docker pretty well: https://docksal.io/ ● All the Drupal Console commands: https://docs.drupalconsole.com/en/commands/available-commands.html ● All the Drush 8 commands: https://drushcommands.com/

  56. Conclusion

  57. Questions

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend