Set the anchor class
public setLinkClass ( mixed $class ) : void | ||
$class | mixed | An array of class names, or a single string class name. |
return | void |
/** * * @param type $hook * @param type $type * @param type $returnvalue * @param type $params * @return ElggMenuItem */ function user_hover_hook($hook, $type, $returnvalue, $params) { $user = $params['entity']; $url = elgg_get_site_url() . "activity_tabs/user/{$user->username}"; $item = new \ElggMenuItem('activity_tabs_user_activity', elgg_echo('activity_tabs'), $url); if ($type == 'menu:user_hover') { $item->setSection('action'); $item->setLinkClass('activity-tabs-user-hover'); $item->setPriority(200); } $returnvalue[] = $item; return $returnvalue; }
/** * ElggMenuItem factory method * * This static method creates an ElggMenuItem from an associative array. * Required keys are name, text, and href. * * @param array $options Option array of key value pairs * * @return ElggMenuItem or null on error */ public static function factory($options) { if (!isset($options['name']) || !isset($options['text'])) { return null; } if (!isset($options['href'])) { $options['href'] = ''; } $item = new ElggMenuItem($options['name'], $options['text'], $options['href']); unset($options['name']); unset($options['text']); unset($options['href']); // special catch in case someone uses context rather than contexts if (isset($options['context'])) { $options['contexts'] = $options['context']; unset($options['context']); } // make sure contexts is set correctly if (isset($options['contexts'])) { $item->setContext($options['contexts']); unset($options['contexts']); } if (isset($options['link_class'])) { $item->setLinkClass($options['link_class']); unset($options['link_class']); } elseif (isset($options['class'])) { elgg_deprecated_notice("ElggMenuItem::factory() does not accept 'class' key anymore, use 'link_class' instead", 1.9); $item->setLinkClass($options['class']); unset($options['class']); } if (isset($options['item_class'])) { $item->setItemClass($options['item_class']); unset($options['item_class']); } if (isset($options['data']) && is_array($options['data'])) { $item->setData($options['data']); unset($options['data']); } foreach ($options as $key => $value) { if (isset($item->data[$key])) { $item->data[$key] = $value; } else { $item->{$key} = $value; } } return $item; }
/** * ElggMenuItem factory method * * This static method creates an ElggMenuItem from an associative array. * Required keys are name, text, and href. * * @param array $options Option array of key value pairs * * @return ElggMenuItem or NULL on error */ public static function factory($options) { if (!isset($options['name']) || !isset($options['text'])) { return NULL; } if (!isset($options['href'])) { $options['href'] = ''; } $item = new ElggMenuItem($options['name'], $options['text'], $options['href']); unset($options['name']); unset($options['text']); unset($options['href']); // special catch in case someone uses context rather than contexts if (isset($options['context'])) { $options['contexts'] = $options['context']; unset($options['context']); } // make sure contexts is set correctly if (isset($options['contexts'])) { $item->setContext($options['contexts']); unset($options['contexts']); } if (isset($options['link_class'])) { $item->setLinkClass($options['link_class']); unset($options['link_class']); } if (isset($options['item_class'])) { $item->setItemClass($options['item_class']); unset($options['item_class']); } if (isset($options['data']) && is_array($options['data'])) { $item->setData($options['data']); unset($options['data']); } foreach ($options as $key => $value) { if (isset($item->data[$key])) { $item->data[$key] = $value; } else { $item->{$key} = $value; } } return $item; }
/** * add 'not spammer' and 'delete' links to entity menuy of listed spammers * * @param type $hook * @param type $type * @param type $return * @param type $params */ function tu_spam_report_spammer_menu($hook, $type, $return, $params) { if (!elgg_instanceof($params['entity'], 'user') || elgg_get_context() != 'reported_spammers') { return $return; } // delete (requires new action due to it being deactivated) $href = elgg_add_action_tokens_to_url('action/reported_spam/delete?guid=' . $params['entity']->guid); $delete = new ElggMenuItem('delete', elgg_view_icon('delete'), $href); $delete->setLinkClass('elgg-requires-confirmation'); // unspam - will unmark this as spam and reactivate it $href = elgg_add_action_tokens_to_url('action/reported_spam/notspammer?guid=' . $params['entity']->guid); $unspam = new ElggMenuItem('unspam', elgg_echo('tu_spam_report:notspammer'), $href); $unspam->setLinkClass('elgg-requires-confirmation'); $metadata = elgg_get_metadata(array('guid' => $params['entity']->guid, 'metadata_name' => 'disable_reason', 'metadata_value' => 'content_marked_spam', 'limit' => false)); $href = false; $reported = new ElggMenuItem('reported', elgg_echo('tu_spam_report:reported', array(date('m/d/Y', $metadata[0]->time_created))), $href); $return[] = $reported; $return[] = $unspam; $return[] = $delete; return $return; }
/** * Setup the default user hover menu * @access private */ function elgg_user_hover_menu($hook, $type, $return, $params) { $user = $params['entity']; if (elgg_is_logged_in()) { if (elgg_get_logged_in_user_guid() != $user->guid) { if ($user->isFriend()) { $url = "action/friends/remove?friend={$user->guid}"; $text = elgg_echo('friend:remove'); $name = 'remove_friend'; } else { $url = "action/friends/add?friend={$user->guid}"; $text = elgg_echo('friend:add'); $name = 'add_friend'; } $url = elgg_add_action_tokens_to_url($url); $item = new ElggMenuItem($name, $text, $url); $item->setSection('action'); $return[] = $item; } else { $url = "profile/{$user->username}/edit"; $item = new ElggMenuItem('profile:edit', elgg_echo('profile:edit'), $url); $item->setSection('action'); $return[] = $item; $url = "avatar/edit/{$user->username}"; $item = new ElggMenuItem('avatar:edit', elgg_echo('avatar:edit'), $url); $item->setSection('action'); $return[] = $item; } } // prevent admins from banning or deleting themselves if (elgg_get_logged_in_user_guid() == $user->guid) { return $return; } if (elgg_is_admin_logged_in()) { $actions = array(); if (!$user->isBanned()) { $actions[] = 'ban'; } else { $actions[] = 'unban'; } $actions[] = 'delete'; $actions[] = 'resetpassword'; if (!$user->isAdmin()) { $actions[] = 'makeadmin'; } else { $actions[] = 'removeadmin'; } foreach ($actions as $action) { $url = "action/admin/user/{$action}?guid={$user->guid}"; $url = elgg_add_action_tokens_to_url($url); $item = new ElggMenuItem($action, elgg_echo($action), $url); $item->setSection('admin'); $item->setLinkClass('elgg-requires-confirmation'); $return[] = $item; } $url = "profile/{$user->username}/edit"; $item = new ElggMenuItem('profile:edit', elgg_echo('profile:edit'), $url); $item->setSection('admin'); $return[] = $item; $url = "settings/user/{$user->username}"; $item = new ElggMenuItem('settings:edit', elgg_echo('settings:edit'), $url); $item->setSection('admin'); $return[] = $item; } return $return; }
function au_landing_title_menu($hook, $type, $return, $params) { if ($type != 'menu:title') { return $return; } if (elgg_get_context() != 'group_profile') { return $return; } $group = elgg_get_page_owner_entity(); if ($group->canEdit() && elgg_is_active_plugin('group_tools')) { $item = new ElggMenuItem('mail', elgg_echo('group_tools:menu:mail'), 'groups/mail/' . $group->getGUID()); $item->setLinkClass('elgg-button elgg-button-action'); $return[] = $item; } return $return; }
function au_theme_titlemenu($h, $t, $r, $p) { $threshold = elgg_get_plugin_setting('compact_title_button_threshold', 'au_theme'); if (!$threshold) { $threshold = 1; } if ($t == 'menu:title' && count($r) > $threshold) { $count = 0; foreach ($r as $key => $button) { if ($button->inContext()) { $count++; } } if ($count <= $threshold) { return $r; } // add in our top level element 'Actions' // everything else gets added as a child of that $text = elgg_echo('au_theme:titledropdown') . '<span class="elgg-icon elgg-icon-round-plus"></span>'; $item = new ElggMenuItem('action-dropdown', $text, '#'); $item->setLinkClass('action-dropdown'); foreach ($r as $key => $button) { if ($button->inContext()) { $item->addChild($button); } } return array($item); } }
public function testAddLinkClassWithArray() { $item = new \ElggMenuItem('name', 'text', 'url'); $item->setLinkClass('new-link'); $item->addLinkClass(array('2nd-link')); $this->assertEquals('new-link 2nd-link', $item->getLinkClass()); }
function ec_ical_pagesetup() { $use_titlemenu = get_input('ical_calendar_title_menu', false); if ($use_titlemenu && elgg_is_logged_in()) { $filter = get_input('ical_calendar_filter', false); $date = get_input('ical_date', false); $interval = get_input('ical_interval', false); $group_guid = get_input('ical_group_guid', false); $export_url = elgg_get_site_url() . 'event_calendar/ical/export?method=ical'; $import_url = elgg_get_site_url() . 'event_calendar/ical/import?method=ical'; $urlsuffix = ''; if ($filter) { $urlsuffix .= "&filter={$filter}"; } if ($date) { $urlsuffix .= "&date={$date}"; } if ($interval) { $urlsuffix .= "&interval={$interval}"; } if ($group_guid !== false) { $urlsuffix .= "&group_guid={$group_guid}"; } $export = new ElggMenuItem('ical_export', elgg_echo('event_calendar:export'), $export_url . $urlsuffix); $export->setLinkClass('elgg-button elgg-button-action'); $import = new ElggMenuItem('ical_import', elgg_echo('event_calendar:import'), $import_url . $urlsuffix); $import->setLinkClass('elgg-button elgg-button-action'); elgg_register_menu_item('title', $export); elgg_register_menu_item('title', $import); } }
/** * Setup the default user hover menu * @access private */ function elgg_user_hover_menu($hook, $type, $return, $params) { $user = $params['entity']; if (elgg_is_logged_in()) { if (elgg_get_logged_in_user_guid() != $user->guid) { $isFriend = $user->isFriend(); // Always emit both to make it super easy to toggle with ajax $return[] = ElggMenuItem::factory(array('name' => 'remove_friend', 'href' => elgg_add_action_tokens_to_url("action/friends/remove?friend={$user->guid}"), 'text' => elgg_echo('friend:remove'), 'section' => 'action', 'item_class' => $isFriend ? '' : 'hidden')); $return[] = ElggMenuItem::factory(array('name' => 'add_friend', 'href' => elgg_add_action_tokens_to_url("action/friends/add?friend={$user->guid}"), 'text' => elgg_echo('friend:add'), 'section' => 'action', 'item_class' => $isFriend ? 'hidden' : '')); } else { $url = "profile/{$user->username}/edit"; $item = new ElggMenuItem('profile:edit', elgg_echo('profile:edit'), $url); $item->setSection('action'); $return[] = $item; $url = "avatar/edit/{$user->username}"; $item = new ElggMenuItem('avatar:edit', elgg_echo('avatar:edit'), $url); $item->setSection('action'); $return[] = $item; } } // prevent admins from banning or deleting themselves if (elgg_get_logged_in_user_guid() == $user->guid) { return $return; } if (elgg_is_admin_logged_in()) { $actions = array(); if (!$user->isBanned()) { $actions[] = 'ban'; } else { $actions[] = 'unban'; } $actions[] = 'delete'; $actions[] = 'resetpassword'; if (!$user->isAdmin()) { $actions[] = 'makeadmin'; } else { $actions[] = 'removeadmin'; } foreach ($actions as $action) { $url = "action/admin/user/{$action}?guid={$user->guid}"; $url = elgg_add_action_tokens_to_url($url); $item = new ElggMenuItem($action, elgg_echo($action), $url); $item->setSection('admin'); $item->setLinkClass('elgg-requires-confirmation'); $return[] = $item; } $url = "profile/{$user->username}/edit"; $item = new ElggMenuItem('profile:edit', elgg_echo('profile:edit'), $url); $item->setSection('admin'); $return[] = $item; $url = "settings/user/{$user->username}"; $item = new ElggMenuItem('settings:edit', elgg_echo('settings:edit'), $url); $item->setSection('admin'); $return[] = $item; } return $return; }