stanford drupal camp 15+ ways to debug drupal 8 · stanford drupal camp 15+ ways to debug drupal 8...

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

Upload: others

Post on 24-Jun-2020

45 views

Category:

Documents


0 download

TRANSCRIPT

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

Stanford Drupal Camp 15+ Ways to Debug

Drupal 8Zakiya Khabir

Drupal Developer, Chapter Three

Page 2: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · 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

Page 3: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

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

Page 4: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

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

Page 5: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

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

developed

Page 6: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

0. Before You Begin Development…

Page 7: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

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

Page 8: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

Symbols Used in SlidesUse it every day.

Use it sometimes.

Wouldn’t recommend

Requires Xdebug.

Requires Composer.

Page 9: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

1. Error Logs

Page 10: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

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

Page 11: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

2. Browser Developer Tools

Page 12: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

2. Browser Developer Tools

Page 13: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

3. Drupal Debug Settings

Page 15: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

4. Drupal Template Helper

Page 16: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

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

Page 17: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

5. Drupal Console

Page 18: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

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

Page 19: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

6. dump()

Page 20: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

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

Page 21: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

7. Devel + Kint

Page 22: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

7a. Devel + Kint

Page 23: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

7b. Devel + Kint

Page 25: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

8. Devel + Webprofiler

Page 26: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

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

Page 27: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

9. Xdebug

Page 28: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

9. Xdebug

Page 29: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

10. twig_xdebug

Page 30: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

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

Page 31: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

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

Page 32: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

11. vardumper

Page 33: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

11. vardumper

Page 34: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

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

Page 35: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

12. Xdebug with Compiled Files

Page 36: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

12. Xdebug with Compiled Files

Page 37: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

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

Page 38: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

13. Write to File

Page 39: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

13. Write to File

Page 40: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

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

Page 41: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

14. Watchdog/Drupal Logging

Page 42: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

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

Page 43: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

15. CodeSniffer

Page 44: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

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

Page 45: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

16. Your IDE

Page 46: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

16. Your IDE

Page 47: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

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 [email protected]

Page 48: Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8 Zakiya Khabir Drupal Developer, Chapter Three

Questions?