1

Almost everywhere I search I find the following example for using dpm() or sdpm() with the Devel and the Search Krumo modules:

Paste the following code in your theme's template.php file, save, and clear cache.

function foo_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'search_block_form') {
    sdpm($form);
  }
}

This is working fine.

But how can I see the other components, like Menu and its components or any block?

I tried following for menu but it is not working.

function mymodule_menu_link_alter(&$item, $menu) {
   sdpm($menu);
} 
2

hook_menu_link_alter() accepts only one argument in Drupal 7. That's why your code isn't working.

Try the following:

function YOURMODULE_menu_link_alter(&$item) {
  if ($item['menu_name'] == 'YOUR_MENU') {
    dpm($item);
  }
}

I have wrapped it in an if check, since otherwise it would run dpm for all menu links on a page and depending on the amount of links it may cause memory overflow or timeout.

  • Something looks wrong, it is not working. even I did check by removing if statement. I have enabled two menu for check i.e. main-menu and user-menu. any suggestion? – CodeNext Sep 4 '16 at 8:50
  • Did you clear the caches? is the module enabled? – Елин Й. Sep 4 '16 at 8:54
  • Yes, I did clear cache every time. – CodeNext Sep 4 '16 at 8:55
  • I have made a correction on the if statement, $item is an array not an object. But it doesn't solve your problem that the hook isn't called. – Елин Й. Sep 4 '16 at 9:03
  • 1
    dpm() and the likes are useful when you know exactly what you're looking for. If you want to be able to browse all variables that are available at a certain point in the code, I recommend using a debugger (like Xdebug) combined with a good IDE (like PhpStorm). Personally, I haven't touched Devel and Krumo since I got the hang of Xdebug. – marcvangend Sep 4 '16 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.