Menus.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace ColdTrick\EmbedExtended;
  3. /**
  4. * Menus
  5. */
  6. class Menus {
  7. /**
  8. * Add menu item to the embed menu
  9. *
  10. * @param string $hook 'register'
  11. * @param string $type 'menu:embed'
  12. * @param ElggMenuItem[] $return_value the current menu items
  13. * @param array $params supplied params
  14. *
  15. * @return ElggMenuItem[]
  16. */
  17. public static function embedMenuRegister($hook, $type, $return_value, $params) {
  18. $return_value[] = \ElggMenuItem::factory([
  19. 'name' => 'internal_content',
  20. 'text' => elgg_echo('embed_extended:menu:embed:internal_content'),
  21. 'priotity' => 150,
  22. 'data' => ['view' => 'embed_extended/internal_content'],
  23. ]);
  24. return $return_value;
  25. }
  26. /**
  27. * Change menu item in the longtext menu
  28. *
  29. * @param string $hook 'prepare'
  30. * @param string $type 'menu:longtext'
  31. * @param ElggMenuItem[] $return_value the current menu items
  32. * @param array $params supplied params
  33. *
  34. * @return ElggMenuItem[]
  35. */
  36. public static function longtextMenuPrepare($hook, $type, $return_value, $params) {
  37. if (!is_array($return_value)) {
  38. return;
  39. }
  40. foreach ($return_value as $section => $menu_items) {
  41. if (!is_array($menu_items)) {
  42. continue;
  43. }
  44. foreach ($menu_items as $menu_item) {
  45. if ($menu_item->getName() !== 'embed') {
  46. continue;
  47. }
  48. if (elgg_is_xhr()) {
  49. echo elgg_format_element('script', [], 'require(["embed_extended/site"]);');
  50. } else {
  51. elgg_require_js('embed_extended/site');
  52. }
  53. $link_class = $menu_item->getLinkClass();
  54. $link_class = str_ireplace('elgg-lightbox', 'elgg-embed-lightbox', $link_class);
  55. $menu_item->setLinkClass($link_class);
  56. }
  57. }
  58. }
  59. }