Hooks.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Elgg\DevelopersPlugin;
  3. /**
  4. * Plugin hook handlers for Developers plugin
  5. */
  6. class Hooks {
  7. /**
  8. * Alter input of menu sections in "gear" popup
  9. *
  10. * @param string $hook 'view_vars'
  11. * @param string $type 'navigation/menu/elements/section'
  12. * @param array $value Menu section $vars
  13. * @param array $params Hook params
  14. *
  15. * @return mixed
  16. */
  17. public static function alterMenuSectionVars($hook, $type, $value, $params) {
  18. // I would avoid using context, but we have to use it already for alterMenuSections()
  19. if (!elgg_in_context('developers_gear')) {
  20. return;
  21. }
  22. $value['class'] = preg_replace('~(^|\\s)elgg-menu-page($|\\s)~', '$1elgg-menu-gear$2', $value['class']);
  23. return $value;
  24. }
  25. /**
  26. * Alter output of menu sections in "gear" popup
  27. *
  28. * @param string $hook 'view'
  29. * @param string $type 'navigation/menu/elements/section'
  30. * @param array $output Menu section HTML
  31. * @param array $params Hook params
  32. *
  33. * @return mixed
  34. */
  35. public static function alterMenuSections($hook, $type, $output, $params) {
  36. // I tried avoiding using context, but not enough data is passed down into
  37. // this hook to reason if we're in the gear popup view
  38. if (!elgg_in_context('developers_gear')) {
  39. return;
  40. }
  41. if (false === strpos($params['vars']['class'], 'elgg-child-menu')) {
  42. return "<section>$output</section>";
  43. }
  44. }
  45. }