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

15 ways to debug drupal 8
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Stanford Drupal Camp

15+ Ways to Debug Drupal 8

Zakiya Khabir Drupal Developer, Chapter Three

slide-2
SLIDE 2

Why this talk?

  • End of dpm()
  • Kint complaints
  • Rumors of a better way
slide-3
SLIDE 3

Audience

  • D7 front-enders
  • New to Drupal
  • Current D8 devs
slide-4
SLIDE 4

Goals

  • Show examples in action
  • Provide references
  • Start a dialog
  • Teach 1 thing
slide-5
SLIDE 5

Disclaimer

  • One person’s experience
  • Mileage may vary
  • Some tools are still being

developed

slide-6
SLIDE 6
  • 0. Before You Begin

Development…

slide-7
SLIDE 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
slide-8
SLIDE 8

Symbols Used in Slides

Use it every day. Use it sometimes. Wouldn’t recommend Requires Xdebug. Requires Composer.

slide-9
SLIDE 9
  • 1. Error Logs
slide-10
SLIDE 10
  • 1. Error Logs

Find path to log at /admin/reports/status/php Make sure error reporting is on!

slide-11
SLIDE 11
  • 2. Browser Developer

Tools

slide-12
SLIDE 12
  • 2. Browser Developer Tools
slide-13
SLIDE 13
  • 3. Drupal Debug

Settings

slide-14
SLIDE 14
  • 3. Drupal Debug Settings

Reference: github.com/chapter-three/drupal-8-theming/blob/master/exercise_01- intro-debug.md

slide-15
SLIDE 15
  • 4. Drupal Template

Helper

slide-16
SLIDE 16
  • 5. Drupal Template Helper

Reference: github.com/arshad/drupal-template-helper

slide-17
SLIDE 17
  • 5. Drupal Console
slide-18
SLIDE 18
  • 4. Drupal Console

Docs: hechoendrupal.gitbooks.io/drupal-console/content/en/commands/help.html

slide-19
SLIDE 19
  • 6. dump()
slide-20
SLIDE 20
  • 6. dump()

Reference: twig.sensiolabs.org/doc/functions/dump.html

slide-21
SLIDE 21
  • 7. Devel + Kint
slide-22
SLIDE 22
  • 7a. Devel + Kint
slide-23
SLIDE 23
  • 7b. Devel + Kint
slide-24
SLIDE 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

slide-25
SLIDE 25
  • 8. Devel + Webprofiler
slide-26
SLIDE 26
  • 8. Devel + Webprofiler

Reference: drupalize.me/blog/201406/web-profiler-drupal-8

slide-27
SLIDE 27
  • 9. Xdebug
slide-28
SLIDE 28
  • 9. Xdebug
slide-29
SLIDE 29
  • 10. twig_xdebug
slide-30
SLIDE 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

slide-31
SLIDE 31
  • 10b. twig_xdebug

using {{ breakpoint() }}

slide-32
SLIDE 32
  • 11. vardumper
slide-33
SLIDE 33
  • 11. vardumper
slide-34
SLIDE 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

slide-35
SLIDE 35
  • 12. Xdebug with

Compiled Files

slide-36
SLIDE 36
  • 12. Xdebug with Compiled Files
slide-37
SLIDE 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

slide-38
SLIDE 38
  • 13. Write to File
slide-39
SLIDE 39
  • 13. Write to File
slide-40
SLIDE 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

slide-41
SLIDE 41
  • 14. Watchdog/Drupal

Logging

slide-42
SLIDE 42
  • 14. Watchdog/Drupal Logging

$ drush ws --tail (last 10 watchdog log messages)

slide-43
SLIDE 43
  • 15. CodeSniffer
slide-44
SLIDE 44
  • 15. CodeSniffer

justdrupal.com/php-code-sniffer-in-phpstorm-for-drupal

slide-45
SLIDE 45
  • 16. Your IDE
slide-46
SLIDE 46
  • 16. Your IDE
slide-47
SLIDE 47

Final Thoughts

  • Debugging tools can use a lot
  • f memory. (oh the irony)
  • Good tools and experience

make you better developer.

  • Checkout #drupaltwig on Slack
  • Send feedback to

@zakiyadesigns or zakiya@chapterthree.com

slide-48
SLIDE 48

Questions?