Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8...

Post on 24-Jun-2020

31 views 0 download

Transcript of Stanford Drupal Camp 15+ Ways to Debug Drupal 8 · Stanford Drupal Camp 15+ Ways to Debug Drupal 8...

Stanford Drupal Camp 15+ Ways to Debug

Drupal 8Zakiya 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

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

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

developed

0. Before You Begin Development…

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

Symbols Used in SlidesUse it every day.

Use it sometimes.

Wouldn’t recommend

Requires Xdebug.

Requires Composer.

1. Error Logs

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

2. Browser Developer Tools

2. Browser Developer Tools

3. Drupal Debug Settings

4. Drupal Template Helper

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

5. Drupal Console

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

6. dump()

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

7. Devel + Kint

7a. Devel + Kint

7b. Devel + Kint

8. Devel + Webprofiler

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

9. Xdebug

9. Xdebug

10. twig_xdebug

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

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

11. vardumper

11. vardumper

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

12. Xdebug with Compiled Files

12. Xdebug with Compiled Files

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

13. Write to File

13. Write to File

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

14. Watchdog/Drupal Logging

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

15. CodeSniffer

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

16. Your IDE

16. Your IDE

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

Questions?