TopbarMenu.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace ColdTrick\FriendRequest;
  3. class TopbarMenu {
  4. /**
  5. * Add menu items to the topbar
  6. *
  7. * @param string $hook the name of the hook
  8. * @param string $type the type of the hook
  9. * @param \ElggMenuItem[] $return_value the current return value
  10. * @param array $params supplied params
  11. *
  12. * @return void|\ElggMenuItem[]
  13. */
  14. public static function register($hook, $type, $return_value, $params) {
  15. $user = elgg_get_logged_in_user_entity();
  16. if (empty($user)) {
  17. return;
  18. }
  19. $options = [
  20. 'type' => 'user',
  21. 'count' => true,
  22. 'relationship' => 'friendrequest',
  23. 'relationship_guid' => $user->getGUID(),
  24. 'inverse_relationship' => true,
  25. ];
  26. $count = elgg_get_entities_from_relationship($options);
  27. if (empty($count)) {
  28. return;
  29. }
  30. $return_value[] = \ElggMenuItem::factory([
  31. 'name' => 'friend_request',
  32. 'href' => "friend_request/{$user->username}",
  33. 'text' => elgg_view_icon('user') . elgg_format_element('span', ['class' => 'friend-request-new'], $count),
  34. 'title' => elgg_echo('friend_request:menu'),
  35. 'priority' => 301
  36. ]);
  37. return $return_value;
  38. }
  39. }