list of button htmls, such as ( html_element1, html_element2, ..., html_element_n), * 'id' => id property for ul element * 'class' => class property for ul element * 'flat' => controls the display of the menu as a dropdown or flat buttons * @param $smarty * * @return string - compatible sugarActionMenu structure, such as *
* 1. SugarButton on smarty * * add appendTo to generate button lists * {{sugar_button ... appendTo='buttons'}} * * ,and then create menu * {{sugar_action_menu ... buttons=$buttons ...}} * * 2. Code generate in PHP * ..., * 'buttons' => $buttons, * ... * ),$xtpl); * $template->assign("ACTION_BUTTON", $action_button); * ?> * 3. Passing array to smarty in PHP * $action_button = array( * 'id' => 'id', * 'buttons' => array( * 'assign('action_button', $action_button); * in the template file * {sugar_action_menu params=$action_button} * * 4. Append button element in the Smarty * {php} * $this->append('buttons', "append('buttons', " * * @author Justin Park (jpark@sugarcrm.com) */ function smarty_function_sugar_action_menu($params, &$smarty) { $flat = !empty($params['flat']) ? $params['flat'] : false; if( !empty($params['params']) ) { $addition_params = $params['params']; unset($params['params']); $params = array_merge_recursive($params, $addition_params); } //if buttons have not implemented, it returns empty string; if(empty($params['buttons'])) return ''; if(is_array($params['buttons']) && !$flat) { $menus = array( 'html' => array_shift($params['buttons']), 'items' => array() ); foreach($params['buttons'] as $item) { if(strlen($item)) { array_push($menus['items'],array( 'html' => $item )); } } $action_menu = array( 'id' => !empty($params['id']) ? (is_array($params['id']) ? $params['id'][0] : $params['id']) : '', 'htmlOptions' => array( 'class' => !empty($params['class']) && strpos($params['class'], 'clickMenu') !== false ? $params['class'] : 'clickMenu '. (!empty($params['class']) ? $params['class'] : ''), 'name' => !empty($params['name']) ? $params['name'] : '', ), 'itemOptions' => array( 'class' => (count($menus['items']) == 0) ? 'single' : 'sugar_action_button' ), 'submenuHtmlOptions' => array( 'class' => 'subnav' ), 'items' => array( $menus ) ); require_once('function.sugar_menu.php'); return smarty_function_sugar_menu($action_menu, $smarty); } if (is_array($params['buttons'])) { return ''; } else if(is_array($params)) { return ' '; } return $params['buttons']; } ?>