devel.module 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. <?php
  2. /**
  3. * @file
  4. * This module holds functions useful for Drupal development.
  5. * Please contribute!
  6. */
  7. define('DEVEL_ERROR_HANDLER_NONE', 0);
  8. define('DEVEL_ERROR_HANDLER_STANDARD', 1);
  9. define('DEVEL_ERROR_HANDLER_BACKTRACE_KINT', 2);
  10. define('DEVEL_ERROR_HANDLER_BACKTRACE_DPM', 4);
  11. define('DEVEL_MIN_TEXTAREA', 50);
  12. use Drupal\comment\CommentInterface;
  13. use Drupal\Core\Database\Database;
  14. use Drupal\Core\Database\Query\AlterableInterface;
  15. use Drupal\Core\Entity\EntityInterface;
  16. use Drupal\Core\Form\FormStateInterface;
  17. use Drupal\Core\Logger\RfcLogLevel;
  18. use Drupal\Core\Render\Element;
  19. use Drupal\Core\Utility\Error;
  20. /**
  21. * Implements hook_help().
  22. */
  23. function devel_help($route_name) {
  24. switch ($route_name) {
  25. case 'devel.reinstall':
  26. $output = '<p>' . t('<strong>Warning</strong> - will delete your module tables and configuration.') . '</p>';
  27. $output .= '<p>' . t('Uninstall and then install the selected modules. <code>hook_uninstall()</code> and <code>hook_install()</code> will be executed and the schema version number will be set to the most recent update number.') . '</p>';
  28. return $output;
  29. case 'devel/session':
  30. return '<p>' . t('Here are the contents of your <code>$_SESSION</code> variable.') . '</p>';
  31. case 'devel.state_system_page':
  32. return '<p>' . t('This is a list of state variables and their values. For more information read online documentation of <a href=":documentation">State API in Drupal 8</a>.', array(':documentation' => "https://www.drupal.org/developing/api/8/state")) . '</p>';
  33. }
  34. }
  35. /**
  36. * Implements hook_entity_type_alter().
  37. */
  38. function devel_entity_type_alter(array &$entity_types) {
  39. /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
  40. foreach ($entity_types as $entity_type_id => $entity_type) {
  41. if ($entity_type->hasViewBuilderClass() && $entity_type->hasLinkTemplate('canonical')) {
  42. $entity_type->setLinkTemplate('devel-render', "/devel/$entity_type_id/{{$entity_type_id}}/render");
  43. }
  44. if (($entity_type->getFormClass('default') || $entity_type->getFormClass('edit')) && $entity_type->hasLinkTemplate('edit-form')) {
  45. $entity_type->setLinkTemplate('devel-load', "/devel/$entity_type_id/{{$entity_type_id}}");
  46. }
  47. }
  48. }
  49. /**
  50. * Implements hook_entity_operation().
  51. */
  52. function devel_entity_operation(EntityInterface $entity) {
  53. $operations = array();
  54. if (\Drupal::currentUser()->hasPermission('access devel information')) {
  55. if ($entity->hasLinkTemplate('devel-load')) {
  56. $operations['devel'] = array(
  57. 'title' => t('Devel'),
  58. 'weight' => 100,
  59. 'url' => $entity->toUrl('devel-load'),
  60. );
  61. }
  62. elseif ($entity->hasLinkTemplate('devel-render')) {
  63. $operations['devel'] = array(
  64. 'title' => t('Devel'),
  65. 'weight' => 100,
  66. 'url' => $entity->toUrl('devel-render'),
  67. );
  68. }
  69. }
  70. return $operations;
  71. }
  72. /**
  73. * Sets message.
  74. */
  75. function devel_set_message($msg, $type = NULL) {
  76. if (function_exists('drush_log')) {
  77. drush_log($msg, $type);
  78. }
  79. else {
  80. drupal_set_message($msg, $type, TRUE);
  81. }
  82. }
  83. /**
  84. * Gets error handlers.
  85. */
  86. function devel_get_handlers() {
  87. $error_handlers = \Drupal::config('devel.settings')->get('error_handlers');
  88. if (!empty($error_handlers)) {
  89. unset($error_handlers[DEVEL_ERROR_HANDLER_NONE]);
  90. }
  91. return $error_handlers;
  92. }
  93. /**
  94. * Sets a new error handler or restores the prior one.
  95. */
  96. function devel_set_handler($handlers) {
  97. if (empty($handlers)) {
  98. restore_error_handler();
  99. }
  100. elseif (count($handlers) == 1 && isset($handlers[DEVEL_ERROR_HANDLER_STANDARD])) {
  101. // Do nothing.
  102. }
  103. else {
  104. set_error_handler('backtrace_error_handler');
  105. }
  106. }
  107. /**
  108. * Displays backtrace showing the route of calls to the current error.
  109. *
  110. * @param int $error_level
  111. * The level of the error raised.
  112. * @param string $message
  113. * The error message.
  114. * @param string $filename
  115. * The filename that the error was raised in.
  116. * @param int $line
  117. * The line number the error was raised at.
  118. * @param array $context
  119. * An array that points to the active symbol table at the point the error
  120. * occurred.
  121. */
  122. function backtrace_error_handler($error_level, $message, $filename, $line, $context) {
  123. // Hide stack trace and parameters from unqualified users.
  124. if (!\Drupal::currentUser()->hasPermission('access devel information')) {
  125. // Do what core does in bootstrap.inc and errors.inc.
  126. // (We need to duplicate the core code here rather than calling it
  127. // to avoid having the backtrace_error_handler() on top of the call stack.)
  128. if ($error_level & error_reporting()) {
  129. $types = drupal_error_levels();
  130. list($severity_msg, $severity_level) = $types[$error_level];
  131. $backtrace = debug_backtrace();
  132. $caller = Error::getLastCaller($backtrace);
  133. // We treat recoverable errors as fatal.
  134. _drupal_log_error(array(
  135. '%type' => isset($types[$error_level]) ? $severity_msg : 'Unknown error',
  136. '@message' => $message,
  137. '%function' => $caller['function'],
  138. '%file' => $caller['file'],
  139. '%line' => $caller['line'],
  140. 'severity_level' => $severity_level,
  141. 'backtrace' => $backtrace,
  142. ), $error_level == E_RECOVERABLE_ERROR);
  143. }
  144. return;
  145. }
  146. // Don't respond to the error if it was suppressed with a '@'
  147. if (error_reporting() == 0) {
  148. return;
  149. }
  150. // Don't respond to warning caused by ourselves.
  151. if (preg_match('#Cannot modify header information - headers already sent by \\([^\\)]*[/\\\\]devel[/\\\\]#', $message)) {
  152. return;
  153. }
  154. if ($error_level & error_reporting()) {
  155. // Only write each distinct NOTICE message once, as repeats do not give any
  156. // further information and can choke the page output.
  157. if ($error_level == E_NOTICE) {
  158. static $written = array();
  159. if (!empty($written[$line][$filename][$message])) {
  160. return;
  161. }
  162. $written[$line][$filename][$message] = TRUE;
  163. }
  164. $types = drupal_error_levels();
  165. list($severity_msg, $severity_level) = $types[$error_level];
  166. $backtrace = debug_backtrace();
  167. $caller = Error::getLastCaller($backtrace);
  168. $variables = array(
  169. '%type' => isset($types[$error_level]) ? $severity_msg : 'Unknown error',
  170. '@message' => $message,
  171. '%function' => $caller['function'],
  172. '%file' => $caller['file'],
  173. '%line' => $caller['line'],
  174. );
  175. $msg = t('%type: @message in %function (line %line of %file).', $variables);
  176. // Show message if error_level is ERROR_REPORTING_DISPLAY_SOME or higher.
  177. // (This is Drupal's error_level, which is different from $error_level,
  178. // and we purposely ignore the difference between _SOME and _ALL,
  179. // see #970688!)
  180. if (\Drupal::config('system.logging')->get('error_level') != 'hide') {
  181. $error_handlers = devel_get_handlers();
  182. if (!empty($error_handlers[DEVEL_ERROR_HANDLER_STANDARD])) {
  183. drupal_set_message($msg, ($severity_level <= RfcLogLevel::NOTICE ? 'error' : 'warning'), TRUE);
  184. }
  185. if (!empty($error_handlers[DEVEL_ERROR_HANDLER_BACKTRACE_KINT])) {
  186. print kprint_r(ddebug_backtrace(TRUE, 1), $return = TRUE, $msg);
  187. }
  188. if (!empty($error_handlers[DEVEL_ERROR_HANDLER_BACKTRACE_DPM])) {
  189. dpm(ddebug_backtrace(TRUE, 1), $msg, 'warning');
  190. }
  191. }
  192. \Drupal::logger('php')->log($severity_level, $msg);
  193. }
  194. }
  195. /**
  196. * Implements hook_page_attachments_alter().
  197. */
  198. function devel_page_attachments_alter(&$page) {
  199. if (\Drupal::currentUser()->hasPermission('access devel information') && \Drupal::config('devel.settings')->get('page_alter')) {
  200. dpm($page, 'page');
  201. }
  202. }
  203. /**
  204. * Prints an object using either Kint (if enabled) or devel_print_object().
  205. *
  206. * @param array|object $object
  207. * An array or object to print.
  208. * @param string $prefix
  209. * @todo: this parameter is not needed with Kint.
  210. * Prefix for output items.
  211. *
  212. * @deprecated in Devel 8.x-dev, will be removed before Devel 8.0.
  213. * Use kpr() or devel.dumper service instead.
  214. *
  215. * @TODO remove in https://www.drupal.org/node/2703343
  216. */
  217. function kdevel_print_object($object, $prefix = NULL) {
  218. return kpr($object, TRUE, $prefix);
  219. }
  220. /**
  221. * Wrapper for DevelDumperManager::dump().
  222. *
  223. * Calls the http://www.firephp.org/ fb() function if it is found.
  224. *
  225. * @see \Drupal\devel\DevelDumperManager::dump()
  226. */
  227. function dfb() {
  228. $args = func_get_args();
  229. \Drupal::service('devel.dumper')->dump($args, NULL, 'firephp');
  230. }
  231. /**
  232. * Wrapper for DevelDumperManager::dump().
  233. *
  234. * Calls dfb() to output a backtrace.
  235. *
  236. * @see \Drupal\devel\DevelDumperManager::dump()
  237. */
  238. function dfbt($label) {
  239. \Drupal::service('devel.dumper')->dump(FirePHP::TRACE, $label, 'firephp');
  240. }
  241. /**
  242. * Wrapper for DevelDumperManager::dump().
  243. *
  244. * Wrapper for ChromePHP Class log method.
  245. *
  246. * @see \Drupal\devel\DevelDumperManager::dump()
  247. */
  248. function dcp() {
  249. $args = func_get_args();
  250. \Drupal::service('devel.dumper')->dump($args, NULL, 'chromephp');
  251. }
  252. if (!function_exists('dd')) {
  253. /**
  254. * Wrapper for DevelDumperManager::debug().
  255. *
  256. * @see \Drupal\devel\DevelDumperManager::debug()
  257. */
  258. function dd($data, $label = NULL) {
  259. return \Drupal::service('devel.dumper')->debug($data, $label, 'default');
  260. }
  261. }
  262. /**
  263. * Wrapper for DevelDumperManager::message().
  264. *
  265. * Prints a variable to the 'message' area of the page.
  266. *
  267. * Uses drupal_set_message().
  268. *
  269. * @param $input
  270. * An arbitrary value to output.
  271. * @param string $name
  272. * Optional name for identifying the output.
  273. * @param string $type
  274. * Optional message type for drupal_set_message(), defaults to 'status'.
  275. *
  276. * @return input
  277. * The unaltered input value.
  278. *
  279. * @see \Drupal\devel\DevelDumperManager::message()
  280. */
  281. function dpm($input, $name = NULL, $type = 'status') {
  282. \Drupal::service('devel.dumper')->message($input, $name, $type);
  283. return $input;
  284. }
  285. /**
  286. * Wrapper for DevelDumperManager::message().
  287. *
  288. * Displays a Variable::export() variable to the 'message' area of the page.
  289. *
  290. * Uses drupal_set_message().
  291. *
  292. * @param $input
  293. * An arbitrary value to output.
  294. * @param string $name
  295. * Optional name for identifying the output.
  296. *
  297. * @return input
  298. * The unaltered input value.
  299. *
  300. * @see \Drupal\devel\DevelDumperManager::message()
  301. */
  302. function dvm($input, $name = NULL) {
  303. \Drupal::service('devel.dumper')->message($input, $name, 'status', 'drupal_variable');
  304. return $input;
  305. }
  306. /**
  307. * An alias for dpm(), for historic reasons.
  308. */
  309. function dsm($input, $name = NULL) {
  310. return dpm($input, $name);
  311. }
  312. /**
  313. * Wrapper for DevelDumperManager::dumpOrExport().
  314. *
  315. * An alias for the devel.dumper service. Saves carpal tunnel syndrome.
  316. *
  317. * @see \Drupal\devel\DevelDumperManager::dumpOrExport()
  318. */
  319. function dpr($input, $export = FALSE, $name = NULL) {
  320. return \Drupal::service('devel.dumper')->dumpOrExport($input, $name, $export, 'default');
  321. }
  322. /**
  323. * Wrapper for DevelDumperManager::dumpOrExport().
  324. *
  325. * An alias for devel_dump(). Saves carpal tunnel syndrome.
  326. *
  327. * @see \Drupal\devel\DevelDumperManager::dumpOrExport()
  328. */
  329. function kpr($input, $export = FALSE, $name = NULL) {
  330. return \Drupal::service('devel.dumper')->dumpOrExport($input, $name, $export);
  331. }
  332. /**
  333. * Kint print.
  334. *
  335. * @deprecated in Devel 8.x-dev, will be removed before Devel 8.0.
  336. * Use kpr() or devel.dumper service instead.
  337. *
  338. * @TODO remove in https://www.drupal.org/node/2703343
  339. */
  340. function kprint_r($input, $export = FALSE, $name = NULL, $function = 'print_r') {
  341. return kpr($input, $export, $name);
  342. }
  343. /**
  344. * Wrapper for DevelDumperManager::dumpOrExport().
  345. *
  346. * Like dpr(), but uses Variable::export() instead.
  347. *
  348. * @see \Drupal\devel\DevelDumperManager::dumpOrExport()
  349. */
  350. function dvr($input, $export = FALSE, $name = NULL) {
  351. return \Drupal::service('devel.dumper')->dumpOrExport($input, $name, $export, 'drupal_variable');
  352. }
  353. /**
  354. * Prints the arguments passed into the current function.
  355. */
  356. function dargs($always = TRUE) {
  357. static $printed;
  358. if ($always || !$printed) {
  359. $bt = debug_backtrace();
  360. print kdevel_print_object($bt[1]['args']);
  361. $printed = TRUE;
  362. }
  363. }
  364. /**
  365. * Prints a SQL string from a DBTNG Select object. Includes quoted arguments.
  366. *
  367. * @param object $query
  368. * An object that implements the SelectInterface interface.
  369. * @param boolean $return
  370. * Whether to return the string. Default is FALSE, meaning to print it
  371. * and return $query instead.
  372. * @param string $name
  373. * Optional name for identifying the output.
  374. *
  375. * @return object|string
  376. * The $query object, or the query string if $return was TRUE.
  377. */
  378. function dpq($query, $return = FALSE, $name = NULL) {
  379. if (\Drupal::currentUser()->hasPermission('access devel information')) {
  380. if (method_exists($query, 'preExecute')) {
  381. $query->preExecute();
  382. }
  383. $sql = (string) $query;
  384. $quoted = array();
  385. $connection = Database::getConnection();
  386. foreach ((array) $query->arguments() as $key => $val) {
  387. $quoted[$key] = is_null($val) ? 'NULL' : $connection->quote($val);
  388. }
  389. $sql = strtr($sql, $quoted);
  390. if ($return) {
  391. return $sql;
  392. }
  393. dpm($sql, $name);
  394. }
  395. return ($return ? NULL : $query);
  396. }
  397. /**
  398. * Prints a renderable array element to the screen using kprint_r().
  399. *
  400. * #pre_render and/or #post_render pass-through callback for kprint_r().
  401. *
  402. * @todo Investigate appending to #suffix.
  403. * @todo Investigate label derived from #id, #title, #name, and #theme.
  404. */
  405. function devel_render() {
  406. $args = func_get_args();
  407. // #pre_render and #post_render pass the rendered $element as last argument.
  408. kprint_r(end($args));
  409. // #pre_render and #post_render expect the first argument to be returned.
  410. return reset($args);
  411. }
  412. /**
  413. * Prints the function call stack.
  414. *
  415. * @param $return
  416. * Pass TRUE to return the formatted backtrace rather than displaying it in
  417. * the browser via kprint_r().
  418. * @param $pop
  419. * How many items to pop from the top of the stack; useful when calling from
  420. * an error handler.
  421. * @param $options
  422. * Options to pass on to PHP's debug_backtrace().
  423. *
  424. * @return string|NULL
  425. * The formatted backtrace, if requested, or NULL.
  426. *
  427. * @see http://php.net/manual/en/function.debug-backtrace.php
  428. */
  429. function ddebug_backtrace($return = FALSE, $pop = 0, $options = DEBUG_BACKTRACE_PROVIDE_OBJECT) {
  430. if (\Drupal::currentUser()->hasPermission('access devel information')) {
  431. $backtrace = debug_backtrace($options);
  432. while ($pop-- > 0) {
  433. array_shift($backtrace);
  434. }
  435. $counter = count($backtrace);
  436. $path = $backtrace[$counter - 1]['file'];
  437. $path = substr($path, 0, strlen($path) - 10);
  438. $paths[$path] = strlen($path) + 1;
  439. $paths[DRUPAL_ROOT] = strlen(DRUPAL_ROOT) + 1;
  440. $nbsp = "\xC2\xA0";
  441. // Show message if error_level is ERROR_REPORTING_DISPLAY_SOME or higher.
  442. // (This is Drupal's error_level, which is different from $error_level,
  443. // and we purposely ignore the difference between _SOME and _ALL,
  444. // see #970688!)
  445. if (\Drupal::config('system.logging')->get('error_level') != 'hide') {
  446. while (!empty($backtrace)) {
  447. $call = array();
  448. if (isset($backtrace[0]['file'])) {
  449. $call['file'] = $backtrace[0]['file'];
  450. foreach ($paths as $path => $len) {
  451. if (strpos($backtrace[0]['file'], $path) === 0) {
  452. $call['file'] = substr($backtrace[0]['file'], $len);
  453. }
  454. }
  455. $call['file'] .= ':' . $backtrace[0]['line'];
  456. }
  457. if (isset($backtrace[1])) {
  458. if (isset($backtrace[1]['class'])) {
  459. $function = $backtrace[1]['class'] . $backtrace[1]['type'] . $backtrace[1]['function'] . '()';
  460. }
  461. else {
  462. $function = $backtrace[1]['function'] . '()';
  463. }
  464. $backtrace[1] += array('args' => array());
  465. foreach ($backtrace[1]['args'] as $key => $value) {
  466. $call['args'][$key] = $value;
  467. }
  468. }
  469. else {
  470. $function = 'main()';
  471. $call['args'] = $_GET;
  472. }
  473. $nicetrace[($counter <= 10 ? $nbsp : '') . --$counter . ': ' . $function] = $call;
  474. array_shift($backtrace);
  475. }
  476. if ($return) {
  477. return $nicetrace;
  478. }
  479. kprint_r($nicetrace);
  480. }
  481. }
  482. }
  483. /*
  484. * Migration-related functions.
  485. */
  486. /**
  487. * Regenerates the data in node_comment_statistics table.
  488. * Technique - http://www.artfulsoftware.com/infotree/queries.php?&bw=1280#101
  489. *
  490. * @return void
  491. */
  492. function devel_rebuild_node_comment_statistics() {
  493. // Empty table.
  494. db_truncate('node_comment_statistics')->execute();
  495. // TODO: DBTNG. Ignore keyword is Mysql only? Is only used in the rare case
  496. // when two comments on the same node share same timestamp.
  497. $sql = "
  498. INSERT IGNORE INTO {node_comment_statistics} (nid, cid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) (
  499. SELECT c.nid, c.cid, c.created, c.name, c.uid, c2.comment_count FROM {comment} c
  500. JOIN (
  501. SELECT c.nid, MAX(c.created) AS created, COUNT(*) AS comment_count FROM {comment} c WHERE status = 1 GROUP BY c.nid
  502. ) AS c2 ON c.nid = c2.nid AND c.created = c2.created
  503. )";
  504. db_query($sql, array(':published' => CommentInterface::PUBLISHED));
  505. // Insert records into the node_comment_statistics for nodes that are missing.
  506. $query = db_select('node', 'n');
  507. $query->leftJoin('node_comment_statistics', 'ncs', 'ncs.nid = n.nid');
  508. $query->addField('n', 'changed', 'last_comment_timestamp');
  509. $query->addField('n', 'uid', 'last_comment_uid');
  510. $query->addField('n', 'nid');
  511. $query->addExpression('0', 'comment_count');
  512. $query->addExpression('NULL', 'last_comment_name');
  513. $query->isNull('ncs.comment_count');
  514. db_insert('node_comment_statistics', array('return' => Database::RETURN_NULL))
  515. ->from($query)
  516. ->execute();
  517. }
  518. /**
  519. * Implements hook_form_FORM_ID_alter().
  520. *
  521. * Adds mouse-over hints on the Permissions page to display
  522. * language-independent machine names and module base names.
  523. *
  524. * @see \Drupal\user\Form\UserPermissionsForm::buildForm()
  525. */
  526. function devel_form_user_admin_permissions_alter(&$form, FormStateInterface $form_state) {
  527. if (\Drupal::currentUser()->hasPermission('access devel information') && \Drupal::config('devel.settings')->get('raw_names')) {
  528. foreach (Element::children($form['permissions']) as $key) {
  529. if (isset($form['permissions'][$key][0])) {
  530. $form['permissions'][$key][0]['#wrapper_attributes']['title'] = $key;
  531. }
  532. elseif(isset($form['permissions'][$key]['description'])) {
  533. $form['permissions'][$key]['description']['#wrapper_attributes']['title'] = $key;
  534. }
  535. }
  536. }
  537. }
  538. /**
  539. * Implements hook_form_FORM_ID_alter().
  540. *
  541. * Adds mouse-over hints on the Modules page to display module base names.
  542. *
  543. * @see \Drupal\system\Form\ModulesListForm::buildForm()
  544. * @see theme_system_modules_details()
  545. */
  546. function devel_form_system_modules_alter(&$form, FormStateInterface $form_state) {
  547. if (\Drupal::currentUser()->hasPermission('access devel information') && \Drupal::config('devel.settings')->get('raw_names', FALSE) && isset($form['modules']) && is_array($form['modules'])) {
  548. foreach (Element::children($form['modules']) as $group) {
  549. if (is_array($form['modules'][$group])) {
  550. foreach (Element::children($form['modules'][$group]) as $key) {
  551. if (isset($form['modules'][$group][$key]['name']['#markup'])) {
  552. $form['modules'][$group][$key]['name']['#markup'] = '<span title="' . $key . '">' . $form['modules'][$group][$key]['name']['#markup'] . '</span>';
  553. }
  554. }
  555. }
  556. }
  557. }
  558. }
  559. /**
  560. * Implements hook_query_TAG_alter().
  561. *
  562. * Makes debugging entity query much easier.
  563. *
  564. * Example usage:
  565. * @code
  566. * $query = \Drupal::entityQuery('node');
  567. * $query->condition('status', NODE_PUBLISHED);
  568. * $query->addTag('debug');
  569. * $query->execute();
  570. * @endcode
  571. */
  572. function devel_query_debug_alter(AlterableInterface $query) {
  573. if (!$query->hasTag('debug-semaphore')) {
  574. $query->addTag('debug-semaphore');
  575. dpq($query);
  576. }
  577. }