15 ways to debug drupal 8
play

15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter - PowerPoint PPT Presentation

Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three Why this talk? End of dpm() Kint complaints Rumors of a better way Audience D7 front-enders New to Drupal Current D8 devs


  1. Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

  2. Why this talk? • End of dpm() • Kint complaints • Rumors of a better way

  3. Audience • D7 front-enders • New to Drupal • Current D8 devs

  4. Goals • Show examples in action • Provide references • Start a dialog • Teach 1 thing

  5. Disclaimer • One person’s experience • Mileage may vary • Some tools are still being developed

  6. 0. Before You Begin Development…

  7. 0. Before You Begin Development • Know how to increase memory limit • drupal.org/docs/7/managing-site-performance-and- scalability/changing-php-memory-limits • Learn composer • http://knpuniversity.com/composer • digitalatolson.com/blog/code/using-composer-with- drupal-8-0 • Know the difference between array, object, and method syntax

  8. Symbols Used in Slides Use it every day. Use it sometimes. Wouldn’t recommend Requires Composer. Requires Xdebug.

  9. 1. Error Logs

  10. 1. Error Logs Find path to log at /admin/reports/status/php Make sure error reporting is on!

  11. 2. Browser Developer Tools

  12. 2. Browser Developer Tools

  13. 3. Drupal Debug Settings

  14. 3. Drupal Debug Settings Reference: github.com/chapter-three/drupal-8-theming/blob/master/exercise_01- intro-debug.md

  15. 4. Drupal Template Helper

  16. 5. Drupal Template Helper Reference: github.com/arshad/drupal-template-helper

  17. 5. Drupal Console

  18. 4. Drupal Console Docs: hechoendrupal.gitbooks.io/drupal-console/content/en/commands/help.html

  19. 6. dump()

  20. 6. dump() Reference: twig.sensiolabs.org/doc/functions/dump.html

  21. 7. Devel + Kint

  22. 7a. Devel + Kint

  23. 7b. Devel + Kint

  24. 7. Devel + Kint notes: • use search_kint • In templates: {{ kint(var) }} {{ dsm(var) }} • In php files: kint($var) ksm($var) • For less memory: drupal.stackexchange.com/ questions/211928/how-can-i-make-kint-load- faster-when-debugging-twig-templates

  25. 8. Devel + Webpro fi ler

  26. 8. Devel + Webprofiler Reference: drupalize.me/blog/201406/web-profiler-drupal-8

  27. 9. Xdebug

  28. 9. Xdebug

  29. 10. twig_xdebug

  30. 10a. twig_xdebug Use Composer to install. drupal.org/project/twig_xdebug Step by Step: chapterthree.com/blog/debug-drupal-8-twig-templates-twigxdebug-module

  31. 10b. twig_xdebug using {{ breakpoint() }}

  32. 11. vardumper

  33. 11. vardumper

  34. 11. vardumper notes: • installed with composer (not composer manager) • Block and console modules aren’t in the recommended package. Product description page has errors. • Not significantly better than kint, ksm. • PHP’s vardumper library is included in DrupalVM by default

  35. 12. Xdebug with Compiled Files

  36. 12. Xdebug with Compiled Files

  37. 12. Xdebug with Compiled Files notes: “ Remember that you are debugging generated php files. This has some implications in comparison to “usual” php files: • After every template change the new php file is re-generated. This results in more than one php file in the generated folder of the Twig template. It may be confusing to determine the “actual” php file we want debug, as the generated php filenames are hashed. The quickest way to get around this is to set a breakpoint to all php files in the directory, at the beginning of doDisplay() function. Then you should surely match one. • If you change anything in a Twig template, the corresponding hashed php file will be newly generated. To debug this file, you must firstly let the php file be generated (e.g. by reloading the page with a new template), then locate this newly generated php file and set the breakpoint inside. • Clearing the cache removes all the folder contents completely. Thus, you must set all the breakpoints again to the newly generated php files. After cache clear • the generated files are not writeable. All changes must be done inside of the Twig templates, not in the generated PHP files! ” - Lubomir Culen , dev.acquia.com/blog/debugging-drupal-8/debugging-twig-templates-in- drupal-8-with-phpstorm-and-xdebug/25/08/2016/16586

  38. 13. Write to File

  39. 13. Write to File

  40. 13. Write to File notes: in php: $fp = fopen(DRUPAL_ROOT . '/file.txt', 'w'); fwrite($fp, print_r($variables, TRUE)); fwrite($fp, print_r("--END--\n", TRUE)); fclose($fp); in terminal: $ cd path/to/drupal $ tail -f file.txt

  41. 14. Watchdog/Drupal Logging

  42. 14. Watchdog/Drupal Logging $ drush ws --tail (last 10 watchdog log messages)

  43. 15. CodeSni ff er

  44. 15. CodeSni ff er justdrupal.com/php-code-sniffer-in-phpstorm-for-drupal

  45. 16. Your IDE

  46. 16. Your IDE

  47. Final Thoughts • Debugging tools can use a lot of memory. (oh the irony) • Good tools and experience make you better developer. • Checkout #drupaltwig on Slack • Send feedback to @zakiyadesigns or zakiya@chapterthree.com

  48. 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