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

Drupal Debug - Improve your developer experience

Drupal Debug - Improve your developer experience

Thomas Calvet

June 13, 2019
Tweet

More Decks by Thomas Calvet

Other Decks in Programming

Transcript

  1. Developer experience 3 Drupal Dev Days Transylvania - Drupal Debug:

    improve your developer experience • Kind of the same concept than the User eXperience applied to development • The user is the developer • But we are more demanding • And the scope is larger
  2. Drupal DX has even more aspects 4 Drupal Dev Days

    Transylvania - Drupal Debug: improve your developer experience • Several developer profiles • Site builder • Theme builder • Custom module maker
  3. So, whatisthe topic today? 5 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience
  4. This talk is about 6 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience • Your custom code • Daily development • Avoid repetitive tasks • Help new Drupal developers
  5. This talk is not about 7 Drupal Dev Days Transylvania

    - Drupal Debug: improve your developer experience • Admin part • Core architecture / code • Documentation • Contribution
  6. Examplesof DX features 8 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience
  7. Provide shortcuts 9 Drupal Dev Days Transylvania - Drupal Debug:

    improve your developer experience • Abstract implementations • Functions, methods, classes, traits • The goal is to hide a complexity
  8. Throw exceptions 10 Drupal Dev Days Transylvania - Drupal Debug:

    improve your developer experience • Handle common users mistakes • Be defensive • Throw an exception • With an useful message
  9. Simple things 11 Drupal Dev Days Transylvania - Drupal Debug:

    improve your developer experience • A small UI change • An up to date PHPDoc • Rename a test class • Etc.
  10. Why does it matter? 13 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience • Less frustration • Increased productivity • A better reputation • Attract more users
  11. Return on experience 14 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience
  12. Who am I? 15 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience • Thomas Calvet - fancyweb • 6 years experience in PHP • Long time Symfony user and enthusiast • New Drupal developer
  13. Drupalisnot readyfor developmentout of the box 16 Drupal Dev Days

    Transylvania - Drupal Debug: improve your developer experience
  14. Missing concepts 17 Drupal Dev Days Transylvania - Drupal Debug:

    improve your developer experience • No « debug » mode • No « environment » management
  15. Display exceptions and errors 19 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience sites/default content
  16. Display exceptions and errors 20 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience Step 1
  17. Display exceptions and errors 21 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience Step 2
  18. Display exceptions and errors 22 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience Step 3
  19. Display exceptions and errors 23 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience Step 4
  20. Display exceptions and errors 24 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience • A basic and common need • Way too many steps for a new Drupal developer • It should be enabled from the start in local
  21. Drupal cache system 25 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience 13 tables of cache data
  22. Drupal cache system 26 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience Cache data content is unreadable
  23. Drupal cache system 27 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience Clearable caches with drush
  24. Drupal cache system 28 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience • Hard to master • Lots of terms : internal, dynamic, Twig, render, keys, tags, context, max age • Even way harder to understand for the front developers
  25. It leads to bad habits 29 Drupal Dev Days Transylvania

    - Drupal Debug: improve your developer experience • You must clear a cache but you don’t know which one • So you clear all cache • Precious seconds wasted everytime
  26. From the community 31 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience • Drupal console commands • drush commands • Devel module
  27. From the core 32 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience • D8DX: Improving the D8 developer experience https://www.drupal.org/community-initiatives/drupal-core/d8dx • List DX issues • Provide a common vocabulary
  28. ekino/drupal-debug https://github.com/ekino/drupal-debug 34 Drupal Dev Days Transylvania - Drupal Debug:

    improve your developer experience • Open source third party library • Improve your DX during the development process • Help you develop better and faster • Reuse well known and well tested open source components
  29. Provide actions 35 Drupal Dev Days Transylvania - Drupal Debug:

    improve your developer experience • An action is a class that does something • Each action has an unique goal • 16 actions at the moment
  30. Disable CSS & JS aggregations 37 Drupal Dev Days Transylvania

    - Drupal Debug: improve your developer experience Before After
  31. Disable CSS & JS aggregations 38 Drupal Dev Days Transylvania

    - Drupal Debug: improve your developer experience What it replaces
  32. Override Drupal configuration 39 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience • Global $config variable • Normally, you modify it in the settings.php file • The library just overrides everything after the settings initialization
  33. Disable Drupal caches 41 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience What it replaces
  34. Override Drupal settings 42 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience • Settings class singleton • Normally, you modify it in the settings.php file • The library just overrides everything after the settings initialization
  35. Enable Twig debug 44 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience Before After
  36. Enable Twig debug 45 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience What it replaces
  37. Override Twig configuration 46 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience • Twig configuration is defined by parameters • Override those parameters before the container compilation • Twig cache is also disabled with this way
  38. Display more information in a prettierway 47 Drupal Dev Days

    Transylvania - Drupal Debug: improve your developer experience
  39. Display pretty exceptions 48 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience Before
  40. Display pretty exceptions 49 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience After
  41. Display pretty exceptions 50 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience • Use Symfony HttpKernel component ExceptionListener • Use Symfony Debug component ExceptionHandler • Available after the environment boot, so very early
  42. Enable Debug class loader 51 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience Provide better exceptions messages for case sensitive filesystems
  43. Enable Debug class loader 52 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience • Use the Symfony Debug component DebugClassLoader class • Wrap your autoloader (a Composer ClassLoader instance most likely) • Also does lightweight static analysis when a class is loaded
  44. Display dump location 53 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience Before
  45. Display dump location 54 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience After
  46. Display dump location 55 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience • Use the Symfony VarDumper component • Define a custom handler
  47. Throw errors as exceptions 57 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience Code example
  48. Throw errors as exceptions 58 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience Before
  49. Throw errors as exceptions 59 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience After
  50. Throw errors as exceptions 60 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience • PHP errors must be handled • Use the Symfony Debug Component ErrorHandler class • Set a custom error handler that rethrow PHP errors as exceptions
  51. Enable Twig strict variables 61 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience Code example
  52. Enable Twig strict variables 62 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience Before
  53. Enable Twig strict variables 63 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience After
  54. Watch actions 65 Drupal Dev Days Transylvania - Drupal Debug:

    improve your developer experience • Detect files creation, alteration and deletion • Invalidate a cache • 3 actions at the moment
  55. Watch container definitions 66 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience Default watched files
  56. Watch modules hooks implementation 67 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience Default watched file
  57. Watch routing definitions 68 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience Default watched file
  58. Watch systems 69 Drupal Dev Days Transylvania - Drupal Debug:

    improve your developer experience • A file resource is tied to an extension (a module or a theme) • A resources freshness checker system • A file cache system • A file backend cache system
  59. It could not be a module 71 Drupal Dev Days

    Transylvania - Drupal Debug: improve your developer experience • Modules are handled too late in the boot • Some actions would be impossible to implement • It would need to be enabled on first use • It would need to be managed to not be used on production
  60. Use an alternative Kernel 72 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience Drupal front controller
  61. Use an alternative Kernel 73 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience • Extend the Drupal Kernel • Dispatch events • Alter the container definitions
  62. How does the substitution work? 75 Drupal Dev Days Transylvania

    - Drupal Debug: improve your developer experience • Create a copy of the DrupalKernel on the fly • Use another name • Replace __DIR__ references • Alias the DrupalKernel with our DebugKernel
  63. The substitution is great 76 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience • The library works out of the box • The Debug Kernel is used by any third party library that woud normally use the Drupal Kernel
  64. The substitution is bad 77 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience • Compatibility problems • Disable it to test a behavior with caches enabled • Disable it for all your tests
  65. Default configuration 79 Drupal Dev Days Transylvania - Drupal Debug:

    improve your developer experience • Some actions are configurable with options • Not mandatory because there are defaults values • Configuration is done in a YAML file • Some with environment variables
  66. Requirements 81 Drupal Dev Days Transylvania - Drupal Debug: improve

    your developer experience • Composer • PHP >= 7.1 (last supported stable version) • Drupal >= 8.6
  67. Improvements 83 Drupal Dev Days Transylvania - Drupal Debug: improve

    your developer experience • On existing actions • Optional actions (opened PR) • Configuration by action (opened PR)
  68. More actions and features 84 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience • Watch themes hooks implementations • Watch libraries (JS & CSS files) • Support third parties actions (opened PR)
  69. The hidden goal 85 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience • A wake up call! • To have a debug mode in the Drupal core • To have more DX initiatives in the Drupal core
  70. An enriching experience 87 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience • For me • For Drupal • For Symfony
  71. Is the community interested? 88 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience • Is it useful for a lot of developers? • Find first users and testers • Eventually find contributors
  72. WHAT DID YOU THINK? Locate this session at the Drupal

    Developer Days Transylvania 2019 website: https://cluj2019.drupaldays.org/schedule Take the survey! https://www.surveymonkey.com/r/drupaltransylvania THANK YOU!