kint.module 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. use Drupal\Core\Render\Markup;
  3. /**
  4. * Alias of Kint::dump().
  5. *
  6. * Prints passed argument(s) using Kint debug tool.
  7. */
  8. function kint() {
  9. kint_require();
  10. if (\Drupal::currentUser()->hasPermission('access kint')) {
  11. $args = func_get_args();
  12. if (PHP_SAPI === 'cli') {
  13. s($args);
  14. }
  15. else {
  16. \Kint::dump($args);
  17. }
  18. }
  19. }
  20. /**
  21. * Alias of Kint::trace().
  22. *
  23. * Prints backtrace in Kint debug tool.
  24. */
  25. function kint_trace() {
  26. kint_require();
  27. if (\Drupal::currentUser()->hasPermission('access kint')) {
  28. call_user_func_array(array('Kint', 'trace'), array());
  29. }
  30. }
  31. /**
  32. * Alias of Kint::kintLite().
  33. *
  34. * Prints with lightweight formatting, using whitespace for formatting instead
  35. * of HTML.
  36. */
  37. function kint_lite() {
  38. if (\Drupal::currentUser()->hasPermission('access kint')) {
  39. $args = func_get_args();
  40. call_user_func_array('kintLite', $args);
  41. }
  42. }
  43. /**
  44. * Prints passed argument(s) to the 'message' area of the page.
  45. */
  46. function ksm() {
  47. kint_require();
  48. if (\Drupal::currentUser()->hasPermission('access kint')) {
  49. $args = func_get_args();
  50. $msg = @Kint::dump($args);
  51. drupal_set_message(Markup::create($msg));
  52. }
  53. }
  54. /**
  55. * Load the Kint class.
  56. */
  57. function kint_require() {
  58. return require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'kint') . '/kint/Kint.class.php';
  59. }