1

I'm working on developing a custom module for Drupal 7. Part of the module that I'm creating is a form editing component (with an entirely different aim from something like cck, which is why I am re-inventing the wheel here). I've got one page registered to display a list of all the forms, and another registered for viewing and editing a specific form. I would like the breadcrumb on the viewing page to include a link to the listing page, however it does not appear. I am getting "Home » Administration » Jarrow ETD System", while I would like to have a "Form Editor" component on the end. The relevant hook_menu code looks like this:

$items['admin/settings/jarrow'] = array(
  'title' => t('Jarrow ETD System'),
  'description' => t('Configure the core settings for the Jarrow ETD system'),
  'page callback' => 'drupal_get_form',
  'page arguments' => array('jarrow_configure'),
  'access arguments' => array('administer etd'),
  'type' => MENU_NORMAL_ITEM,
);

$items['admin/settings/jarrow/forms'] = array(
  'title' => t('Form Editor'),
  'description' => t('View All Forms'),
  'page callback' => 'jarrow_list_forms',
  'file' => 'form_editor.inc',
  'access callback' => 'user_access',
  'access arguments' => array('administer etd'),
  'type' => MENU_LOCAL_TASK,
  'weight' => 40,
);

$items['admin/settings/jarrow/forms/%/view'] = array(
  'title' => t('Form View'),
  'description' => t('View a Form'),
  'page callback' => 'jarrow_view_form',
  'page arguments' => array(4),
  'file' => 'form_editor.inc',
  'access callback' => 'user_access',
  'access arguments' => array('administer etd'),
  'type' => MENU_NORMAL_ITEM,
);

There are a significant number of other pages registered, which I have omitted. Aside from the fact that I probably shouldn't be using 'admin/settings' as my base url, I can't see anything wrong with the menu structure. Oddly enough, if I add in the following code to hook_menu, I get the right result:

$items['admin/settings/jarrow/stuff'] = array(
  'title' => t('Stuff Editor'),
  'description' => t('View All Forms'),
  'page callback' => 'jarrow_list_forms',
  'file' => 'form_editor.inc',
  'access callback' => 'user_access',
  'access arguments' => array('administer etd'),
  'type' => MENU_LOCAL_TASK,
  'weight' => 40,
);

  $items['admin/settings/jarrow/stuff/%/view'] = array(
  'title' => t('Stuff View'),
  'description' => t('View a Form'),
  'page callback' => 'jarrow_view_form',
  'page arguments' => array(4),
  'file' => 'form_editor.inc',
  'access callback' => 'user_access',
  'access arguments' => array('administer etd'),
  'type' => MENU_NORMAL_ITEM,
);

This is exactly the same entry into hook_menu, down to the function it's calling, except for the url having "stuff" in it instead of "forms". However, the breadcrumb trail displays properly: "Home » Administration » Jarrow ETD System » Stuff Editor".

I took a look at the inner workings of menu.inc, and traced the execution. It appears that when Drupal assembles the menu tree for the form, it is including the child /view, whereas for "stuff" it does not. I can't for the life of me figure out why, and I am hoping someone with experience dealing with drupal's menu system can provide some explanation as to why the menu would be constructed as such.

1 Answer 1

0

After making a completely unrelated change to my hook_menu, the breadcrumb fixed itself. I don't know why though.

2
  • My theory: the menu system is broken. The reason why there is no relevant documentation (that I can find) is because there is no consistent way to get items to appear in breadcrumbs. As soon as one tries to document a solution, one finds an exception. The exceptions are not consistent, and inexplicably, the system sometimes (but not always) heals itself. Even posting a good bug report would be difficult, since it is hard to consistently reproduce the problem. If anyone finds a solution, or a consistent way to reproduce the problem, please post.
    – arnoldbird
    Sep 13, 2013 at 15:01
  • In my case, I believe I was able to make some progress by deleting problematic menu items from the menu_links table. Breadcrumbs then appear as desired when the parent and children items are all of type MENU_NORMAL_ITEM in the code (though I'm not sure the type matters), and the URLs are set up like so... parent, parent/child, parent/child2, etc. When I do this and clear the cache, breadcrumbs then appear as they should. Items are re-created in the menu_links table, but not with the same IDs; this could break some sites as a result, if you have code that depends on the menu link IDs.
    – arnoldbird
    Sep 13, 2013 at 16:00

Your Answer

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

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