EntityMenu.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace ColdTrick\SiteAnnouncements;
  3. class EntityMenu {
  4. /**
  5. * Change the entity menu items for site announcements
  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 (empty($params) || !is_array($params)) {
  16. return $returnvalue;
  17. }
  18. $entity = elgg_extract("entity", $params);
  19. if (empty($entity) || !elgg_instanceof($entity, "object", SITE_ANNOUNCEMENT_SUBTYPE)) {
  20. return $returnvalue;
  21. }
  22. if (elgg_in_context("site_announcements_header")) {
  23. // site menu
  24. $returnvalue = array();
  25. $returnvalue[] = \ElggMenuItem::factory(array(
  26. "name" => "mark",
  27. "text" => elgg_view_icon("delete"),
  28. "title" => elgg_echo("site_announcements:menu:entity:mark"),
  29. "href" => "action/site_announcements/mark?guid=" . $entity->getGUID(),
  30. "rel" => $entity->getGUID(),
  31. "is_action" => true
  32. ));
  33. } else {
  34. // admin has different items than site
  35. $allowed_menu_items = array("access", "edit", "delete");
  36. foreach ($returnvalue as $index => $menu_item) {
  37. if (!in_array($menu_item->getName(), $allowed_menu_items)) {
  38. unset($returnvalue[$index]);
  39. }
  40. }
  41. }
  42. return $returnvalue;
  43. }
  44. }