BxBaseStudioMenu.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  8. * @{
  9. */
  10. class BxBaseStudioMenu extends BxDolStudioMenu
  11. {
  12. protected $_bMenuSide;
  13. protected $_bInlineIcons;
  14. public function __construct ($aObject, $oTemplate)
  15. {
  16. parent::__construct ($aObject, $oTemplate);
  17. $this->_bMenuSide = $this->_aObject['template'] == 'menu_side.html';
  18. $this->_bInlineIcons = in_array($this->_aObject['template'], array(
  19. 'menu_side.html',
  20. 'menu_top_toolbar.html',
  21. 'menu_launcher_browser.html',
  22. 'page_breadcrumb.html'
  23. ));
  24. }
  25. public function setInlineIcons($bInlineIcons)
  26. {
  27. $this->_bInlineIcons = $bInlineIcons;
  28. }
  29. protected function _getMenuItem ($aItem)
  30. {
  31. $aItem = parent::_getMenuItem($aItem);
  32. if($aItem === false)
  33. return $aItem;
  34. $aItem['class'] = isset($aItem['class']) ? $aItem['class'] : '';
  35. if($this->_bInlineIcons && $aItem['bx_if:image']['condition'] && strpos($aItem['icon'], '.svg') !== false) {
  36. $aItem = array_merge($aItem, array(
  37. 'bx_if:image' => array (
  38. 'condition' => false,
  39. 'content' => array(),
  40. ),
  41. 'bx_if:image_inline' => array (
  42. 'condition' => true,
  43. 'content' => array(
  44. 'image' => file_get_contents($this->_oTemplate->getIconPath($aItem['icon']))
  45. ),
  46. ),
  47. ));
  48. }
  49. if($this->_bMenuSide) {
  50. $aItem['bx_if:show_icon'] = [
  51. 'condition' => $aItem['bx_if:icon']['condition'] || $aItem['bx_if:image']['condition'] || $aItem['bx_if:image_inline']['condition'],
  52. 'content' => []
  53. ];
  54. $aItem['bx_if:show_icon_bg'] = [
  55. 'condition' => (isset($aItem['icon_bg']) && $aItem['icon_bg'] === true) || strpos($aItem['icon'], '.') === false,
  56. 'content' => []
  57. ];
  58. }
  59. return $aItem;
  60. }
  61. /**
  62. * Check if menu items is selected.
  63. * @param $a menu item array
  64. * @return boolean
  65. */
  66. protected function _isSelected ($a)
  67. {
  68. return isset($a['selected']) && $a['selected'] === true;
  69. }
  70. }
  71. /** @} */