gyro/core/view/widgets/menuitem.widget.php
Go to the documentation of this file.00001 <?php 00002 /** 00003 * A widget printing one menu item. 00004 * 00005 * This widget resuses the templates widgets/menu/action and widgets/menu/command 00006 * depending on the type of the given action 00007 * 00008 * @author Gerd Riesselmann 00009 * @ingroup View 00010 */ 00011 class WidgetItemMenuItem implements IWidget { 00012 public $action; 00013 00014 /** 00015 * Convenience wrapper 00016 * 00017 * @param IAction $action 00018 */ 00019 public static function output($action, $policy = self::NONE) { 00020 $w = new WidgetItemMenuItem($action); 00021 return $w->render($policy); 00022 } 00023 00024 public function __construct($action) { 00025 $this->action = $action; 00026 } 00027 00028 public function render($policy = self::NONE) { 00029 $ret = ''; 00030 $is_command = ($this->action instanceof ICommand); 00031 $template = $is_command ? 'widgets/menu/command' : 'widgets/menu/action'; 00032 $view = ViewFactory::create_view(IViewFactory::MESSAGE, $template); 00033 $view->assign('action', $this->action); 00034 if ($is_command) { 00035 Load::tools('formhandler'); 00036 $formhandler = new FormHandler('process_commands', 'process_commands', FormHandler::TOKEN_POLICY_REUSE); 00037 $formhandler->prepare_view($view); 00038 } 00039 00040 $ret = $view->render(); 00041 return $ret; 00042 } 00043 }