Skip to content

Commit

Permalink
Have server_add turn the "Add Photo" menu option into a dropdown and
Browse files Browse the repository at this point in the history
make "Add from Server" a 2nd option there.

This requires adding the Menu::remove() API function.
  • Loading branch information
bharat committed Jun 2, 2009
1 parent ffb3abd commit e834c4c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
13 changes: 12 additions & 1 deletion modules/gallery/libraries/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,22 @@ public function add_after($target_id, $new_menu_element) {
return $this;
}

/**
* Remove an element from the menu
*/
public function remove($target_id) {
unset($this->elements[$target_id]);
}

/**
* Retrieve a Menu_Element by id
*/
public function get($id) {
return $this->elements[$id];
if (array_key_exists($id, $this->elements)) {
return $this->elements[$id];
}

return null;
}

public function __toString() {
Expand Down
34 changes: 29 additions & 5 deletions modules/server_add/helpers/server_add_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,35 @@ static function site($menu, $theme) {
$paths = unserialize(module::get_var("server_add", "authorized_paths"));

if (user::active()->admin && $item->is_album() && !empty($paths)) {
$options_menu = $menu->get("options_menu")
->append(Menu::factory("dialog")
->id("server_add")
->label(t("Add from server"))
->url(url::site("server_add/index/$item->id")));
// This is a little tricky. Normally there's an "Add Photo" menu option, but we want to
// turn that into a dropdown if there are two different ways to add things. Do that in a
// portable way for now. If we find ourselves duplicating this pattern, we should make an
// API method for this.
$server_add = Menu::factory("dialog")
->id("server_add")
->label(t("Add from server"))
->url(url::site("server_add/index/$item->id"));
$options_menu = $menu->get("options_menu");
$add_item = $options_menu->get("add_item");
$add_menu = $options_menu->get("add_menu");

if ($add_item && !$add_menu) {
// Assuming that $add_menu is unset, create add_menu and add our item
$options_menu->add_after(
"add_item",
Menu::factory("submenu")
->id("add_menu")
->label(t("Add"))
->append($add_item)
->append($server_add));
$options_menu->remove("add_item");
} else if ($add_menu) {
// Append to the existing sub-menu
$add_menu->append($server_add);
} else {
// Else just add it in at the end of Options
$options_menu->append($server_add);
}
}
}
}

0 comments on commit e834c4c

Please sign in to comment.