diff --git a/hansel.actions.inc b/hansel.actions.inc index a5059c4136824af93d69ca2bec751f531189fa72..97031ec8369bca1983d2b6b100f0e5dbcafe7d01 100644 --- a/hansel.actions.inc +++ b/hansel.actions.inc @@ -273,6 +273,35 @@ function menu_hansel_get_parent($path) { return FALSE; } +/** + * Implements hook_hansel_get_parent(). + * + * @param string $path + * @return array + */ +function path_hansel_get_parent($path) { + if (variable_get('hansel_parent_lookup_paths', TRUE)) { + $alias = drupal_get_path_alias($_GET['q']); + if ($alias != $_GET['q']) { + $alias = substr($alias, 0, strrpos($alias, '/')); + if (!($path = drupal_lookup_path($alias))) { + // The alias is probably a valid system path. + $path = $alias; + } + if (!$parent_path = drupal_lookup_path($path)) { + $parent_path = $path; + } + if ($item = menu_get_item($parent_path)) { + return array( + 'path' => $parent_path, + 'title' => $item['title'], + ); + } + } + } + return FALSE; +} + /** * Callback for the "add single link" breadcrumb action to generate the config form. * diff --git a/hansel_ui/hansel_ui.module b/hansel_ui/hansel_ui.module index 9e82d4fd48a1fec0ae45e2104865927e180bd955..022644cd0574f2f6e7c215d28bd9f4de7ab217c1 100644 --- a/hansel_ui/hansel_ui.module +++ b/hansel_ui/hansel_ui.module @@ -202,6 +202,13 @@ function hansel_ui_settings($form_state) { '#default_value' => variable_get('hansel_set_menu_name', TRUE), '#description' => t('This is required for the \'leave original breadcrumbs\' option to work for pages which are not in the default menu. Turn this option off if you experience side effects.'), ); + + $form['hansel_parent_lookup_paths'] = array( + '#type' => 'checkbox', + '#title' => t('Lookup url aliases when looking for parents'), + '#default_value' => variable_get('hansel_parent_lookup_paths', TRUE), + '#description' => t('Hansel is able to lookup parents based on url aliases. But this may cost extra database queries. You should disable this feature when not required.'), + ); return system_settings_form($form); }