本文整理匯總了PHP中ElggMenuItem::getSelected方法的典型用法代碼示例。如果您正苦於以下問題:PHP ElggMenuItem::getSelected方法的具體用法?PHP ElggMenuItem::getSelected怎麽用?PHP ElggMenuItem::getSelected使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ElggMenuItem
的用法示例。
在下文中一共展示了ElggMenuItem::getSelected方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: _elgg_site_menu_setup
/**
* Set up the site menu
*
* Handles default, featured, and custom menu items
*
* @access private
*/
function _elgg_site_menu_setup($hook, $type, $return, $params)
{
$featured_menu_names = elgg_get_config('site_featured_menu_names');
$custom_menu_items = elgg_get_config('site_custom_menu_items');
if ($featured_menu_names || $custom_menu_items) {
// we have featured or custom menu items
$registered = $return['default'];
/* @var \ElggMenuItem[] $registered */
// set up featured menu items
$featured = array();
foreach ($featured_menu_names as $name) {
foreach ($registered as $index => $item) {
if ($item->getName() == $name) {
$featured[] = $item;
unset($registered[$index]);
}
}
}
// add custom menu items
$n = 1;
foreach ($custom_menu_items as $title => $url) {
$item = new \ElggMenuItem("custom{$n}", $title, $url);
$featured[] = $item;
$n++;
}
$return['default'] = $featured;
if (count($registered) > 0) {
$return['more'] = $registered;
}
} else {
// no featured menu items set
$max_display_items = 5;
// the first n are shown, rest added to more list
// if only one item on more menu, stick it with the rest
$num_menu_items = count($return['default']);
if ($num_menu_items > $max_display_items + 1) {
$return['more'] = array_splice($return['default'], $max_display_items);
}
}
// check if we have anything selected
$selected = false;
foreach ($return as $section) {
/* @var \ElggMenuItem[] $section */
foreach ($section as $item) {
if ($item->getSelected()) {
$selected = true;
break 2;
}
}
}
if (!$selected) {
// nothing selected, match name to context or match url
$current_url = current_page_url();
foreach ($return as $section_name => $section) {
foreach ($section as $key => $item) {
// only highlight internal links
if (strpos($item->getHref(), elgg_get_site_url()) === 0) {
if ($item->getName() == elgg_get_context()) {
$return[$section_name][$key]->setSelected(true);
break 2;
}
if ($item->getHref() == $current_url) {
$return[$section_name][$key]->setSelected(true);
break 2;
}
}
}
}
}
return $return;
}