class: center, middle # Drupal 8 Webprofiler ### Michael Lenahan ### Drupal-Entwickler bei [erdfisch](erdfish.de), Heidelberg *Shameless plug*: Drupal Camp Heidelberg, April 2016 *date to be confirmed* --- # Webprofiler toolbar ![Webprofiler toolbar](images/webprofiler-1.png) --- # Webprofiler module https://www.drupal.org/project/webprofiler https://www.drupal.org/u/lussoluca https://events.drupal.org/barcelona2015/schedule/2015-09-24 https://events.drupal.org/barcelona2015/sessions/how-drupal-8-builds-your-pages --- # Setup - Install Drupal 8 - Install webprofiler module - (Install examples module) Disable Optimizations if (file_exists(__DIR__ . '/settings.local.php')) { include __DIR__ . '/settings.local.php'; } --- # Webprofiler configuration Data collector plugins IDE Link integration See README in webprofiler/README.md for more tips on IDE links for various OS/IDE combinations. Ubuntu/Sublime-Text IDE Link: http://stackoverflow.com/questions/14676981/sublime-text-url-handler-for-ubuntu --- # Route, Controller This is a route: page_example_simple: path: 'examples/page_example/simple' defaults: _controller: '\Drupal\page_example\Controller\PageExampleController::simple' _title: 'Simple - no arguments' requirements: _permission: 'access simple page' The _controller provides a drupal *render array*, or http response object This is a slightly more complex route, with two arguments: page_example_arguments: path: 'examples/page_example/arguments/{first}/{second}' So, if you go to: examples/page_example/arguments/23/kwatsch You get a 403 response. --- # Route, Controller (2) ... as we said, you get a 403 response. You can see why, in the controller: public function arguments($first, $second) { // Make sure you don't trust the URL to be safe! Always check for exploits. if (!is_numeric($first) || !is_numeric($second)) { // We will just show a standard "access denied" page in this case. throw new AccessDeniedHttpException(); } ... --- # Forms In Drupal 8, all forms are built using the buildForm() method of the Controller. In the webprofiler Form widget, the elements of the Form API array are listed. --- # Services Services contain business logic: - for easy reuse - for easy testing A good example of a service is: cache.backend.null ... in development.services.yml Drupal core has over 500 services defined, each does a specific job: - translate a text - run a database query - send an email - authenticate a user We can see a complete list of all the services in the Services widget. We can see which services have been initialized on this request. INFO --> we can see the dependencies that a service has Count: # of times the service requested Time taken to initialize the service (only initialized once) --- # Databases One example of a service is the database service. This service is so important, it has it's own widget. SWAP PLACEHOLDERS --- # Theme layer Twig timeline and dependencies --- # Data collectors are exensible! Rules module Themekey module Debugging information will be collected using Webprofiler --- # Thank you! Especially lussoluca