0

I have an entity form(theme page to display it) . I have used hook_node_view() to handle breadcrumbs for nodes. But I don't find any place to handle this $breadcrumb when I have a form and a theme page for it.

This is how I got the $breadcrumb for my news.

/**
 * Implements hook_node_view().
 */
function news_node_view($node, $view_mode, $langcode) {
  if ($node->type == 'news' && $view_mode == 'full') {
    //BREADCRUMB ////
    $breadcrumb = array();
    $breadcrumb[] = l('Home', '<front>');
    $breadcrumb[] = l('News', 'news');
    drupal_set_title('News');
    drupal_set_breadcrumb($breadcrumb);
  }
}

I have hook functions like:

hook_init()
hook_menu()
hook_form()
hook_form_validate()
hook_form_submit()
hook_theme()
hook_preprocess_form()

But I don't find a place to work on $breadcrumb, or somehow manage it.

1 Answer 1

0

If you are looking for GUI to handle breadcrumbs, take a look at Custom breadcrumbs module. Otherwise, you can manage your breadcrumbs programatically in lot of hooks. The code you've printed is correct, so you can create for example a function with a switch case like this one :

function manager_breadcrumbs($form_id) {
  $breadcrumb = array();
  $breadcrumb[] = l('Home', '<front>');
  switch ($form_id) {
    case 'my_first_form' :
      $breadcrumb[] = l('Category', 'taxonomy/term/1');
      break;
  }
  drupal_set_breadcrumb($breadcrumb);
}

And then, call this function in a hook_form_alter() like this.

function MY_CUSTOM_MODULE_form_alter(&$form, &$form_state, $form_id) {
  manager_breadcrumbs($form_id);
}
3
  • Thank you for your time. But I have about 16 forms directed to the same theme page. In case, if I am going to try something from the template file, that is just a waste of time. And also, I have to display the breadcrumb something like "Home >> Form Module >> Form Title" Commented Jan 8, 2015 at 13:06
  • If the page show only one form, try using hook_form_alter() instead (I will edit the code above) Commented Jan 8, 2015 at 14:13
  • Thanks, now I got if from my module's code. I have expanded the switch to get things done.[also edited a mistake in switch syntax in your code] Commented Jan 9, 2015 at 4:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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