EntityMenu.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace ColdTrick\BlogTools;
  3. /**
  4. * Router handling
  5. *
  6. * @package ColdTrick
  7. * @subpackage BlogTools
  8. */
  9. class EntityMenu {
  10. /**
  11. * Add some menu items to the entity menu
  12. *
  13. * @param string $hook "register"
  14. * @param string $entity_type "menu:entity"
  15. * @param ElggMenuItem[] $returnvalue the current menu items
  16. * @param array $params supplied params
  17. *
  18. * @return ElggMenuItem[]
  19. */
  20. public static function register($hook, $entity_type, $returnvalue, $params) {
  21. if (empty($params) || !is_array($params)) {
  22. return $returnvalue;
  23. }
  24. $entity = elgg_extract("entity", $params);
  25. if (empty($entity) || !elgg_instanceof($entity, "object", "blog")) {
  26. return $returnvalue;
  27. }
  28. // only published blogs
  29. if ($entity->status == "draft") {
  30. return $returnvalue;
  31. }
  32. if (!elgg_in_context("widgets") && elgg_is_admin_logged_in()) {
  33. $returnvalue[] = \ElggMenuItem::factory(array(
  34. "name" => "blog-feature",
  35. "text" => elgg_echo("blog_tools:toggle:feature"),
  36. "href" => "action/blog_tools/toggle_metadata?guid=" . $entity->getGUID() . "&metadata=featured",
  37. "item_class" => empty($entity->featured) ? "" : "hidden",
  38. "is_action" => true,
  39. "priority" => 175
  40. ));
  41. $returnvalue[] = \ElggMenuItem::factory(array(
  42. "name" => "blog-unfeature",
  43. "text" => elgg_echo("blog_tools:toggle:unfeature"),
  44. "href" => "action/blog_tools/toggle_metadata?guid=" . $entity->getGUID() . "&metadata=featured",
  45. "item_class" => empty($entity->featured) ? "hidden" : "",
  46. "is_action" => true,
  47. "priority" => 176
  48. ));
  49. }
  50. if ($entity->canComment()) {
  51. $returnvalue[] = \ElggMenuItem::factory(array(
  52. "name" => "comments",
  53. "text" => elgg_view_icon("speech-bubble"),
  54. "title" => elgg_echo("comment:this"),
  55. "href" => $entity->getURL() . "#comments"
  56. ));
  57. $comment_count = $entity->countComments();
  58. if ($comment_count) {
  59. $returnvalue[] = \ElggMenuItem::factory(array(
  60. "name" => "comments_count",
  61. "text" => $comment_count,
  62. "title" => elgg_echo("comments"),
  63. "href" => false
  64. ));
  65. }
  66. }
  67. return $returnvalue;
  68. }
  69. }