UserHoverMenu.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace ColdTrick\SiteAnnouncements;
  3. class UserHoverMenu {
  4. /**
  5. * Add a menu item to the user hover menu
  6. *
  7. * @param string $hook the name of the hook
  8. * @param string $type the type of the hook
  9. * @param \ElggMenuItem[] $returnvalue current returnvalue
  10. * @param array $params supplied params
  11. *
  12. * @return \ElggMenuItem[]
  13. */
  14. public static function register($hook, $type, $returnvalue, $params) {
  15. if (!elgg_is_admin_logged_in()) {
  16. return $returnvalue;
  17. }
  18. if (empty($params) || !is_array($params)) {
  19. return $returnvalue;
  20. }
  21. $entity = elgg_extract("entity", $params);
  22. if (empty($entity) || !elgg_instanceof($entity, "user")) {
  23. return $returnvalue;
  24. }
  25. if ($entity->isAdmin()) {
  26. // user is already admin
  27. return $returnvalue;
  28. }
  29. $is_editor = site_announcements_is_editor($entity);
  30. $returnvalue[] = \ElggMenuItem::factory(array(
  31. 'name' => 'announcement_make_editor',
  32. 'text' => elgg_echo('site_announcements:user_hover:make_editor'),
  33. 'href' => "action/site_announcements/toggle_editor?user_guid={$entity->getGUID()}",
  34. 'item_class' => $is_editor ? 'hidden' : '',
  35. 'section' => 'admin',
  36. 'priority' => 400
  37. ));
  38. $returnvalue[] = \ElggMenuItem::factory(array(
  39. 'name' => 'announcement_remove_editor',
  40. 'text' => elgg_echo('site_announcements:user_hover:remove_editor'),
  41. 'href' => "action/site_announcements/toggle_editor?user_guid={$entity->getGUID()}",
  42. 'item_class' => $is_editor ? '' : 'hidden',
  43. 'section' => 'admin',
  44. 'priority' => 401
  45. ));
  46. return $returnvalue;
  47. }
  48. }