summaryrefslogtreecommitdiff
path: root/modules/gallery/libraries/Menu.php
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-10-27 13:46:24 -0700
committerBharat Mediratta <bharat@menalto.com>2009-10-27 13:48:41 -0700
commit76c0c7f3a1246319242e8fff7649c1450da0f98e (patch)
treeb34a559996a5bed898bff3e6006fe377c58889a4 /modules/gallery/libraries/Menu.php
parentab1d21eb34cfca46383ef10b66c49616beb6af15 (diff)
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.
Diffstat (limited to 'modules/gallery/libraries/Menu.php')
-rw-r--r--modules/gallery/libraries/Menu.php61
1 files changed, 16 insertions, 45 deletions
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 "<li><a$css_id class=\"g-menu-link $css_class\" href=\"$this->url\" " .
- "title=\"$this->label\">$this->label</a></li>";
+ 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 "<li><a$css_id class=\"g-ajax-link $css_class\" href=\"$this->url\" " .
- "title=\"$this->label\" ajax_handler=\"$this->ajax_handler\">$this->label</a></li>";
+ 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 "<li><a$css_id class=\"g-dialog-link $css_class\" href=\"$this->url\" " .
- "title=\"$this->label\">$this->label</a></li>";
+ 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 ? "<ul class=\"$this->css_class\">" :
- "<li title=\"$this->label\"><a href=\"#\">$this->label</a><ul>";
- $html .= implode("\n", $this->elements);
- $html .= $this->is_root ? "</ul>" : "</ul></li>";
- return $html;
+ public function render() {
+ $view = new View("menu.html");
+ $view->menu = $this;
+ return $view;
}
}