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

L’expérience développeur dans Drupal 8 : améliorons-la !

L’expérience développeur dans Drupal 8 : améliorons-la !

Thomas Calvet

February 15, 2019
Tweet

More Decks by Thomas Calvet

Other Decks in Programming

Transcript

  1. Developer experience 3 Drupalcamp Paris 2019 - L’expérience développeur dans

    Drupal 8 : améliorons-la ! • 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 Drupalcamp Paris 2019

    - L’expérience développeur dans Drupal 8 : améliorons-la ! • Several developer profiles • Site builder • Theme builder • Custom module maker
  3. So, whatisthe topic today? 5 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la !
  4. This talk is about 6 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! • Your custom code • Daily development • Avoid repetitive tasks • Help new Drupal developers
  5. This talk is not about 7 Drupalcamp Paris 2019 -

    L’expérience développeur dans Drupal 8 : améliorons-la ! • Admin part • Core architecture / code • Documentation • Contribution
  6. Provide shortcuts 9 Drupalcamp Paris 2019 - L’expérience développeur dans

    Drupal 8 : améliorons-la ! • Abstract implementations • Functions, methods, classes, traits • The goal is to hide a complexity
  7. Throw exceptions 10 Drupalcamp Paris 2019 - L’expérience développeur dans

    Drupal 8 : améliorons-la ! • Handle common users mistakes • Be defensive • Throw an exception • With a useful message
  8. Simple things 11 Drupalcamp Paris 2019 - L’expérience développeur dans

    Drupal 8 : améliorons-la ! • A small UI change • An up to date PHPDoc • Rename a test class • Etc.
  9. Why does it matter? 13 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! • Less frustration • Increased productivity • A better reputation • Attract more users
  10. Who am I? 15 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! • Thomas Calvet - fancyweb • 6 years experience in PHP • Long time Symfony user and enthusiast • New Drupal developer
  11. Drupalisnot readyfor developmentout of the box 16 Drupalcamp Paris 2019

    - L’expérience développeur dans Drupal 8 : améliorons-la !
  12. Missing concepts 17 Drupalcamp Paris 2019 - L’expérience développeur dans

    Drupal 8 : améliorons-la ! • No « debug » mode • No « environment »
  13. Display exceptions and errors 19 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! sites/default content
  14. Display exceptions and errors 20 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! Step 1
  15. Display exceptions and errors 21 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! Step 2
  16. Display exceptions and errors 22 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! Step 3
  17. Display exceptions and errors 23 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! Step 4
  18. Display exceptions and errors 24 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! • A basic and common need • Way too many steps for a new Drupal developer • It should be enabled from the start in local
  19. Drupal cache system 25 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! 13 tables of cache data
  20. Drupal cache system 26 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! Cache data content is unreadable
  21. Drupal cache system 27 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! Clearable caches with drush
  22. Drupal cache system 28 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! • Hard to master • Lots of terms : internal, dynamic, Twig, render, keys, tags, context, max age • Even way harder to understand for the front developers
  23. It leads to bad habits 29 Drupalcamp Paris 2019 -

    L’expérience développeur dans Drupal 8 : améliorons-la ! • You must clear a cache but you don’t know which one • So you clear all cache • Precious seconds wasted everytime
  24. From the community 31 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! • Drupal console commands • drush commands • Devel module
  25. From the core 32 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! • D8DX: Improving the D8 developer experience https://www.drupal.org/community-initiatives/drupal-core/d8dx • List DX issues • Provide a common vocabulary
  26. ekino/drupal-debug https://github.com/ekino/drupal-debug 34 Drupalcamp Paris 2019 - L’expérience développeur dans

    Drupal 8 : améliorons-la ! • 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
  27. Provide actions 35 Drupalcamp Paris 2019 - L’expérience développeur dans

    Drupal 8 : améliorons-la ! • An action is a class that does something • Each action has an unique goal • 16 actions at the moment
  28. Disable CSS & JS aggregations 37 Drupalcamp Paris 2019 -

    L’expérience développeur dans Drupal 8 : améliorons-la ! Before After
  29. Disable CSS & JS aggregations 38 Drupalcamp Paris 2019 -

    L’expérience développeur dans Drupal 8 : améliorons-la ! What it replaces
  30. Override Drupal configuration 39 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! • Global $config variable • Normally, you modify it in the settings.php file • The library just override everything after the settings initialization
  31. Disable Drupal caches 41 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! What it replaces
  32. Override Drupal settings 42 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! • Settings class singleton • Normally, you modify it in the settings.php file • The library just override everything after the settings initialization
  33. Enable Twig debug 45 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! What it replaces
  34. Override Twig configuration 46 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! • Twig configuration is defined by parameters • Override those parameters before the container compilation • Twig cache is also disabled with this way
  35. Display more information in a prettierway 47 Drupalcamp Paris 2019

    - L’expérience développeur dans Drupal 8 : améliorons-la !
  36. Display pretty exceptions 50 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! • Use Symfony HttpKernel component ExceptionListener • Use Symfony Debug component ExceptionHandler • Available after the environment boot, so very early
  37. Enable Debug class loader 51 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! Provide better exceptions messages for case sensitive filesystems
  38. Enable Debug class loader 52 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! • 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
  39. Display dump location 55 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! • Use the Symfony VarDumper component • Define a custom handler
  40. Throw errors as exceptions 57 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! Code example
  41. Throw errors as exceptions 58 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! Before
  42. Throw errors as exceptions 59 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! After
  43. Throw errors as exceptions 60 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! • PHP errors must be handled • Use the Symfony Debug Component ErrorHandler class • Set a custom error handler that rethrow PHP errors as exceptions
  44. Enable Twig strict variables 61 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! Code example
  45. Enable Twig strict variables 62 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! Before
  46. Enable Twig strict variables 63 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! After
  47. Watch actions 65 Drupalcamp Paris 2019 - L’expérience développeur dans

    Drupal 8 : améliorons-la ! • Detect files creation, alteration and deletion • Invalidate a cache • 3 actions at the moment
  48. Watch container definitions 66 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! Default watched files
  49. Watch modules hooks implementation 67 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! Default watched file
  50. Watch routing definitions 68 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! Default watched file
  51. Watch systems 69 Drupalcamp Paris 2019 - L’expérience développeur dans

    Drupal 8 : améliorons-la ! • A resources freshness checker system • A file resource is tied to an extension • A file cache system • A file backend cache system
  52. It could not be a module 71 Drupalcamp Paris 2019

    - L’expérience développeur dans Drupal 8 : améliorons-la ! • 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
  53. Use another Kernel 72 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! Drupal front controller
  54. Use an alternative Kernel 73 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! • Extends the Drupal Kernel • Dispatch events • Alter the container definitions
  55. How does the substitution work? 75 Drupalcamp Paris 2019 -

    L’expérience développeur dans Drupal 8 : améliorons-la ! • Create a copy of the DrupalKernel on the fly • Use another name • Replace paths references • Alias the DrupalKernel with our DebugKernel
  56. The substitution is great 76 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! • The library works out of the box • The Debug Kernel is used by any third party library that woud normally use the Drupal Kernel
  57. The substitution is bad 77 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! • Compatibility problems • Disable it to test a behavior with caches enabled • Disable it for all your tests
  58. Default configuration 79 Drupalcamp Paris 2019 - L’expérience développeur dans

    Drupal 8 : améliorons-la ! • Some actions are configurable with options • Not mandatory because there are defaults values • Configuration is done in a YAML file • Some with environment variables
  59. Requirements 81 Drupalcamp Paris 2019 - L’expérience développeur dans Drupal

    8 : améliorons-la ! • Composer • PHP >= 7.1 (last supported stable version) • Drupal >= 8.6 (latest minor version)
  60. Improvements 83 Drupalcamp Paris 2019 - L’expérience développeur dans Drupal

    8 : améliorons-la ! • On existing actions • Optional actions • Configuration by action
  61. More actions and features 84 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! • Watch themes hooks implementations • Watch libraries (JS & CSS files) • Support third parties actions
  62. The hidden goal 85 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! • A wake up call! • To have a debug mode in the Drupal core • To have more DX initiatives in the Drupal core
  63. An enriching experience 87 Drupalcamp Paris 2019 - L’expérience développeur

    dans Drupal 8 : améliorons-la ! • For me • For Drupal • For Symfony
  64. Is the community interested? 88 Drupalcamp Paris 2019 - L’expérience

    développeur dans Drupal 8 : améliorons-la ! • Is it useful for a lot of developers? • Find first users and testers • Eventually find contributors