From 76c0c7f3a1246319242e8fff7649c1450da0f98e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 27 Oct 2009 13:46:24 -0700 Subject: Change our menu building blocks to use PHP templates so that themes can override them and define their own menu formats. I worry a little bit that this approach may be too heavy since we're now doing a lot more template includes than we were before. Also, I had to change the Menu API to stop using __toString() because you can't throw exceptions from __toString() which would make it an unhappy experience for developers. --- modules/gallery/libraries/Menu.php | 61 ++++++++++---------------------------- 1 file changed, 16 insertions(+), 45 deletions(-) (limited to 'modules/gallery/libraries/Menu.php') diff --git a/modules/gallery/libraries/Menu.php b/modules/gallery/libraries/Menu.php index 47af8531..22261557 100644 --- a/modules/gallery/libraries/Menu.php +++ b/modules/gallery/libraries/Menu.php @@ -80,19 +80,10 @@ class Menu_Element { * Menu element that provides a link to a new page. */ class Menu_Element_Link extends Menu_Element { - public function __toString() { - if (isset($this->css_id) && !empty($this->css_id)) { - $css_id = " id=\"$this->css_id\""; - } else { - $css_id = ""; - } - if (isset($this->css_class) && !empty($this->css_class)) { - $css_class = " $this->css_class"; - } else { - $css_class = ""; - } - return "
  • url\" " . - "title=\"$this->label\">$this->label
  • "; + public function render() { + $view = new View("menu_link.html"); + $view->menu = $this; + return $view; } } @@ -111,19 +102,10 @@ class Menu_Element_Ajax_Link extends Menu_Element { return $this; } - public function __toString() { - if (isset($this->css_id) && !empty($this->css_id)) { - $css_id = " id=\"$this->css_id\""; - } else { - $css_id = ""; - } - if (isset($this->css_class) && !empty($this->css_class)) { - $css_class = " $this->css_class"; - } else { - $css_class = ""; - } - return "
  • url\" " . - "title=\"$this->label\" ajax_handler=\"$this->ajax_handler\">$this->label
  • "; + public function render() { + $view = new View("menu_ajax_link.html"); + $view->menu = $this; + return $view; } } @@ -131,19 +113,10 @@ class Menu_Element_Ajax_Link extends Menu_Element { * Menu element that provides a pop-up dialog */ class Menu_Element_Dialog extends Menu_Element { - public function __toString() { - if (isset($this->css_id) && !empty($this->css_id)) { - $css_id = " id=\"$this->css_id\""; - } else { - $css_id = ""; - } - if (isset($this->css_class) && !empty($this->css_class)) { - $css_class = " $this->css_class"; - } else { - $css_class = ""; - } - return "
  • url\" " . - "title=\"$this->label\">$this->label
  • "; + public function render() { + $view = new View("menu_dialog.html"); + $view->menu = $this; + return $view; } } @@ -242,11 +215,9 @@ class Menu_Core extends Menu_Element { return null; } - public function __toString() { - $html = $this->is_root ? ""; - return $html; + public function render() { + $view = new View("menu.html"); + $view->menu = $this; + return $view; } } -- cgit v1.2.3