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

Drupal Debug - Improve your developer experience

Drupal Debug - Improve your developer experience

A7e7c34aaa3ff7eb359b6449fb8bb043?s=128

Thomas Calvet

June 13, 2019
Tweet

Transcript

  1. Drupal Debug Improve your developer experience Thomas Calvet - fancyweb

  2. DevelopereXperience 2 Drupal Dev Days Transylvania - Drupal Debug: improve

    your developer experience
  3. 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
  4. 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
  5. So, whatisthe topic today? 5 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience
  6. 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
  7. This talk is not about 7 Drupal Dev Days Transylvania

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

    Debug: improve your developer experience
  9. 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
  10. 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
  11. 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.
  12. Whydoesitmatter? 12 Drupal Dev Days Transylvania - Drupal Debug: improve

    your developer experience
  13. 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
  14. Return on experience 14 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience
  15. 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
  16. Drupalisnot readyfor developmentout of the box 16 Drupal Dev Days

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

    improve your developer experience • No « debug » mode • No « environment » management
  18. Examples 18 Drupal Dev Days Transylvania - Drupal Debug: improve

    your developer experience
  19. Display exceptions and errors 19 Drupal Dev Days Transylvania -

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

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

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

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

    Drupal Debug: improve your developer experience Step 4
  24. 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
  25. Drupal cache system 25 Drupal Dev Days Transylvania - Drupal

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

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

    Debug: improve your developer experience Clearable caches with drush
  28. 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
  29. 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
  30. Are thereinitiatives? Yes! 30 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience
  31. From the community 31 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience • Drupal console commands • drush commands • Devel module
  32. 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
  33. Proposingsomethingnew 33 Drupal Dev Days Transylvania - Drupal Debug: improve

    your developer experience
  34. 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
  35. 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
  36. Drupaldevelopment configuration 36 Drupal Dev Days Transylvania - Drupal Debug:

    improve your developer experience
  37. Disable CSS & JS aggregations 37 Drupal Dev Days Transylvania

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

    - Drupal Debug: improve your developer experience What it replaces
  39. 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
  40. DisableDrupalcaches 40 Drupal Dev Days Transylvania - Drupal Debug: improve

    your developer experience
  41. Disable Drupal caches 41 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience What it replaces
  42. 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
  43. Twigdevelopment configuration 43 Drupal Dev Days Transylvania - Drupal Debug:

    improve your developer experience
  44. Enable Twig debug 44 Drupal Dev Days Transylvania - Drupal

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

    Debug: improve your developer experience What it replaces
  46. 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
  47. Display more information in a prettierway 47 Drupal Dev Days

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

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

    Debug: improve your developer experience After
  50. 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
  51. Enable Debug class loader 51 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience Provide better exceptions messages for case sensitive filesystems
  52. 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
  53. Display dump location 53 Drupal Dev Days Transylvania - Drupal

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

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

    Debug: improve your developer experience • Use the Symfony VarDumper component • Define a custom handler
  56. Enforcegood practices 56 Drupal Dev Days Transylvania - Drupal Debug:

    improve your developer experience
  57. Throw errors as exceptions 57 Drupal Dev Days Transylvania -

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

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

    Drupal Debug: improve your developer experience After
  60. 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
  61. Enable Twig strict variables 61 Drupal Dev Days Transylvania -

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

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

    Drupal Debug: improve your developer experience After
  64. Invalidatecaches automatically 64 Drupal Dev Days Transylvania - Drupal Debug:

    improve your developer experience
  65. 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
  66. Watch container definitions 66 Drupal Dev Days Transylvania - Drupal

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

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

    Debug: improve your developer experience Default watched file
  69. 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
  70. How doesitwork? 70 Drupal Dev Days Transylvania - Drupal Debug:

    improve your developer experience
  71. 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
  72. Use an alternative Kernel 72 Drupal Dev Days Transylvania -

    Drupal Debug: improve your developer experience Drupal front controller
  73. 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
  74. Substitutingthe original DrupalKernel 74 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience
  75. 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
  76. 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
  77. 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
  78. Configuration 78 Drupal Dev Days Transylvania - Drupal Debug: improve

    your developer experience
  79. 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
  80. Requirements 80 Drupal Dev Days Transylvania - Drupal Debug: improve

    your developer experience
  81. Requirements 81 Drupal Dev Days Transylvania - Drupal Debug: improve

    your developer experience • Composer • PHP >= 7.1 (last supported stable version) • Drupal >= 8.6
  82. What’snext? 82 Drupal Dev Days Transylvania - Drupal Debug: improve

    your developer experience
  83. Improvements 83 Drupal Dev Days Transylvania - Drupal Debug: improve

    your developer experience • On existing actions • Optional actions (opened PR) • Configuration by action (opened PR)
  84. 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)
  85. 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
  86. Final thoughts 86 Drupal Dev Days Transylvania - Drupal Debug:

    improve your developer experience
  87. An enriching experience 87 Drupal Dev Days Transylvania - Drupal

    Debug: improve your developer experience • For me • For Drupal • For Symfony
  88. 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
  89. Thank you, for your attention. Any questions?

  90. https://github.com/ekino/ drupal-debug 90 Drupal Dev Days Transylvania - Drupal Debug:

    improve your developer experience
  91. 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!