BxTemplMenuToolbar.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaTemplate UNA Template Classes
  7. * @{
  8. */
  9. /**
  10. * @see BxDolMenu
  11. */
  12. class BxTemplMenuToolbar extends BxBaseMenuToolbar
  13. {
  14. protected $_aHideFromSiteToolbar;
  15. protected $_aHideFromMemberToolbar;
  16. protected $_bSiteToolbar;
  17. public function __construct ($aObject, $oTemplate = false)
  18. {
  19. parent::__construct ($aObject, $oTemplate);
  20. $this->_aHideFromSiteToolbar = ['search'];
  21. $this->_aHideFromMemberToolbar = [];
  22. $this->_bSiteToolbar = $this->_sObject == 'sys_toolbar_site';
  23. }
  24. protected function _getMenuItem ($a)
  25. {
  26. if(in_array($a['hidden_on'], [7, 15]))
  27. return false;
  28. //--- '[Main Menu]' opens the site sidebar (see the switch below) instead of the sliding menu
  29. if($a['name'] == 'main-menu')
  30. $a['onclick'] = '';
  31. //--- Hide '[Search]' from Site Toolbar
  32. if($this->_bSiteToolbar && in_array($a['name'], $this->_aHideFromSiteToolbar))
  33. return false;
  34. //--- Hide '[+ Add]' from Member Toolbar
  35. if(!$this->_bSiteToolbar && in_array($a['name'], $this->_aHideFromMemberToolbar))
  36. return false;
  37. $a = parent::_getMenuItem ($a);
  38. if($a === false)
  39. return $a;
  40. $a['class_add_a'] = '';
  41. //--- Each of these items is a disclosure: it opens a sidebar or a popup instead of following a link.
  42. $sAttrsAdd = '';
  43. switch ($a['name']) {
  44. case 'main-menu':
  45. //--- The sidebar it opens is for small screens only, wider ones show the main menu inline.
  46. if(isset($a['class_add']))
  47. $a['class_add'] .= ' lg:hidden';
  48. $a['class_add_a'] = ' bx-sidebar-site-trigger';
  49. $a['link'] = 'javascript:void(0)';
  50. $a['onclick'] = '';
  51. $sAttrsAdd = 'aria-haspopup="dialog" aria-expanded="false" aria-controls="bx-sidebar-site"';
  52. break;
  53. case 'account':
  54. $a['class_add_a'] = ' bx-sidebar-account-trigger';
  55. $a['link'] = 'javascript:void(0)';
  56. $a['onclick'] = '';
  57. $sAttrsAdd = 'aria-haspopup="dialog" aria-expanded="false" aria-controls="bx-sidebar-account"';
  58. break;
  59. case 'add-content':
  60. if(isset($a['class_add']))
  61. $a['class_add'] = str_replace('bx-def-media-phone-hide', '', $a['class_add']);
  62. if(isset($a['bx_if:onclick']['content']['onclick']))
  63. $a['bx_if:onclick']['content']['onclick'] = str_replace('bx_menu_slide_inline', 'bx_menu_popup_inline', $a['bx_if:onclick']['content']['onclick']);
  64. $sAttrsAdd = 'aria-haspopup="true" aria-expanded="false" aria-controls="bx-sliding-menu-sys_add_content"';
  65. break;
  66. case 'search':
  67. //--- The app gets the item as it is in the menu builder.
  68. if($this->_bIsApi)
  69. break;
  70. if(isset($a['class_add']))
  71. $a['class_add'] = str_replace('bx-def-media-phone-hide', '', $a['class_add']);
  72. //--- The floating search bar (see _page_toolbar_search.html) takes the button's place. Without it the button opens the search page.
  73. if(getParam('bx_artificer_header_search') == 'on') {
  74. $a['link'] = 'javascript:void(0)';
  75. $a['bx_if:onclick'] = ['condition' => true, 'content' => ['onclick' => 'bx_site_search_show(this)']];
  76. $sAttrsAdd = 'aria-expanded="false" aria-controls="bx-ti-search-box"';
  77. }
  78. else {
  79. $a['link'] = BX_DOL_URL_ROOT . 'searchKeyword.php';
  80. $a['bx_if:onclick'] = ['condition' => false, 'content' => ['onclick' => '']];
  81. }
  82. break;
  83. case 'notifications-preview':
  84. if(isset($a['bx_if:onclick']['content']['onclick']))
  85. $a['bx_if:onclick']['content']['onclick'] = str_replace(["bx_menu_slide", "'site', "], ['bx_menu_popup'], $a['bx_if:onclick']['content']['onclick']);
  86. //--- No aria-controls, because bx_menu_popup() creates the popup lazily and the id does not
  87. //--- exist yet, and no aria-expanded, because the popup is anchored on the ancestor <ul>
  88. //--- rather than on this link, so nothing is in a position to keep the state honest.
  89. $sAttrsAdd = 'aria-haspopup="dialog"';
  90. break;
  91. }
  92. if($sAttrsAdd && isset($a['attrs']))
  93. $a['attrs'] .= ' ' . $sAttrsAdd;
  94. return $a;
  95. }
  96. }
  97. /** @} */