devel.module 21 KB

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