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 (if the value is assigned, it will be not affected by enable_action_menu setting.) * @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) { global $sugar_config; if( !empty($params['params']) ) { $addition_params = $params['params']; unset($params['params']); $params = array_merge_recursive($params, $addition_params); } $flat = isset($params['flat']) ? $params['flat'] : (isset($sugar_config['enable_action_menu']) ? !$sugar_config['enable_action_menu'] : false); //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(is_array($item)) { $sub = array(); $sub_first = array_shift($item); foreach($item as $subitem) { $sub[] = array( 'html' => $subitem ); } array_push($menus['items'],array( 'html' => $sub_first, 'items' => $sub, 'submenuHtmlOptions' => array( 'class' => 'subnav-sub' ) )); } else 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'] : ''), ), 'itemOptions' => array( 'class' => (count($menus['items']) == 0) ? 'single' : 'sugar_action_button' ), 'submenuHtmlOptions' => array( 'class' => 'subnav' ), 'items' => array( $menus ) ); if (!empty($params['name'])) { $action_menu['htmlOptions']['name'] = $params['name']; } 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']; } function implode_r($glue, $pieces, $extract_first_item = false) { $result = array_shift($pieces); if(is_array($result)) { $result = implode_r($glue, $result); } foreach($pieces as $item) { if(is_array($item)) { $result .= empty($extract_first_item) ? implode_r($glue, $item) : $glue.$item[0]; } else { $result .= $glue.$item; } } return $result; } ?>