Commit 7aad04f4 authored by profix898's avatar profix898

- feature: configurable target menu for dynamic link items (#269398)

parent de2e985d
......@@ -107,10 +107,11 @@ function gallery_menu_gallery_page_alter(&$result) {
* Function gallery_menu_build_links().
* (check for existing items and insert/update/delete as suitable)
*/
function gallery_menu_build_links() {
function gallery_menu_build_links($rebuild = FALSE) {
// Derive array of link items from G2 album tree
$items = array();
$depth = variable_get('gallery_menu_depth', 3);
$menu_name = variable_get('gallery_menu_menu', 'navigation');
$tree = gallery_album_tree(NULL, $depth ? $depth : NULL);
_gallery_menu_traverse($tree, $items);
......@@ -118,7 +119,12 @@ function gallery_menu_build_links() {
$olditems = array();
$result = db_query("SELECT link_path FROM {menu_links} WHERE module = '%s' AND link_path LIKE '%s'", 'gallery_menu', variable_get('gallery_base', 'gallery') .'/%');
while ($item = db_fetch_object($result)) {
$olditems[$item->link_path] = $item->link_path;
if ($rebuild) {
menu_link_delete(NULL, $item->link_path);
}
else {
$olditems[$item->link_path] = $item->link_path;
}
}
// Insert/update/delete link items
......@@ -130,12 +136,13 @@ function gallery_menu_build_links() {
}
else {
// Add new item
menu_link_maintain('gallery_menu', 'insert', $item['link_path'], $item['link_title']);
$item['menu_name'] = $menu_name;
menu_link_save($item);
}
}
// Remove obsolete items
foreach ($olditems as $item) {
menu_link_maintain('gallery_menu', 'delete', $item, '');
foreach ($olditems as $link_path) {
menu_link_delete(NULL, $link_path);
}
}
......@@ -157,7 +164,8 @@ function _gallery_menu_traverse($tree, &$items) {
$album = gallery_item_details($id);
$item = array(
'link_title' => $album['title'],
'link_path' => $path
'link_path' => $path,
'module' => 'gallery_menu'
);
$items[] = $item;
if (count($tree[$id])) {
......@@ -217,6 +225,14 @@ function _gallery_menu_settings() {
'#collapsible' => TRUE,
'#collapsed' => TRUE
);
$menus = array_filter(menu_get_menus());
$form['menu']['gallery_menu_menu'] = array(
'#type' => 'select',
'#title' => t('Menu'),
'#default_value' => variable_get('gallery_menu_menu', 'navigation'),
'#options' => $menus,
'#description' => t('Select the menu where gallery menu items will be added.')
);
$form['menu']['gallery_menu_depth'] = array(
'#type' => 'select',
'#title' => t('Depth of Gallery albums'),
......@@ -224,6 +240,11 @@ function _gallery_menu_settings() {
'#options' => _gallery_range_array(1, MENU_MAX_PARTS),
'#description' => 'Depth of album hierarchy to include.'
);
$form['menu']['rebuild_btn'] = array(
'#type' => 'submit',
'#value' => t('Rebuild menu'),
'#rebuild_menu' => TRUE
);
return $form;
}
......@@ -231,8 +252,12 @@ function _gallery_menu_settings() {
/**
* Function _gallery_menu_settings_submit().
*/
function _gallery_menu_settings_submit($form_id, $form_values) {
function _gallery_menu_settings_submit($form, &$form_state) {
// Rebuild album links (router items first, then the actual menu links)
menu_rebuild();
gallery_menu_build_links();
$rebuild = isset($form_state['clicked_button']['#rebuild_menu']);
gallery_menu_build_links($rebuild);
if ($rebuild) {
drupal_set_message(t('Gallery link items have been rebuild.'));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment