BxTemplMenuSite.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 BxTemplMenuMoreAuto
  11. */
  12. class BxTemplMenuSite extends BxTemplMenuMoreAuto
  13. {
  14. protected $_sModule;
  15. protected $_oModule;
  16. protected $_bSiteMenu;
  17. protected $_bSiteMenuInPanel;
  18. protected $_bApplicationMenu;
  19. protected $_aHideFromSiteMenu;
  20. protected $_aHideFromSiteMenuInPanel;
  21. public function __construct ($aObject, $oTemplate = false)
  22. {
  23. parent::__construct ($aObject, $oTemplate);
  24. $this->_sModule = 'bx_artificer';
  25. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  26. $this->_aHideFromSiteMenu = ['search'];
  27. $this->_aHideFromSiteMenuInPanel = ['more-auto'];
  28. $this->_sJsClassMoreAuto = 'BxArtificerMenuMoreAuto';
  29. $this->_bSiteMenu = $this->_sObject == 'sys_site';
  30. $this->_bSiteMenuInPanel = $this->_sObject == 'sys_site_in_panel';
  31. $this->_bApplicationMenu = $this->_sObject == 'sys_application';
  32. if($this->_bSiteMenu) {
  33. $this->_bHx = getParam('bx_artificer_use_htmx') == 'on';
  34. $this->_mHxPreload = $this->_bHx && true;
  35. $this->_aHx = [
  36. 'get' => '',
  37. 'trigger' => 'click',
  38. 'target' => '#bx-content-with-cover-wrapper',
  39. 'swap' => 'outerHTML settle:400ms',
  40. 'push-url' => 'true',
  41. 'on::after:swap' => 'oBxArtificerUtils.mmenuClickAl(this)'
  42. ];
  43. }
  44. }
  45. public function getCode ()
  46. {
  47. $sTemplate = 'menu_main_popup.html';
  48. $sClass = 'bx-popup-menu-main';
  49. $sStyle = 'display:none';
  50. if($this->_bSiteMenu || $this->_bSiteMenuInPanel || $this->_bApplicationMenu) {
  51. $sTemplate = 'menu_main_inline.html';
  52. $sClass = 'bx-inline-smenu-main';
  53. $sStyle = '';
  54. }
  55. $this->_oModule->_oTemplate->addJs(array('menu_site.js'));
  56. return $this->_oModule->_oTemplate->parseHtmlByName($sTemplate, array(
  57. 'id' => 'bx-sliding-menu-' . $this->_sObject,
  58. 'class' => $sClass . ' ' . str_replace('_', '-', $this->_sObject),
  59. 'style' => $sStyle,
  60. 'content' => parent::getCode()
  61. ));
  62. }
  63. protected function _getMenuItem ($a)
  64. {
  65. //--- Hide '[Search]' from Site Menu
  66. if( $this->_bSiteMenu && in_array($a['name'], $this->_aHideFromSiteMenu))
  67. return false;
  68. //--- Hide '[More Auto]' from Site Menu in Panel
  69. if( $this->_bSiteMenuInPanel && in_array($a['name'], $this->_aHideFromSiteMenuInPanel))
  70. return false;
  71. return parent::_getMenuItem ($a);
  72. }
  73. }
  74. /** @} */