Tabs.php 2.45 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
<?php
/*------------------------------------------------------------------------
# SM Mega Menu - Version 3.2.0
# Copyright (c) 2015 YouTech Company. All Rights Reserved.
# @license - Copyrighted Commercial Software
# Author: YouTech Company
# Websites: http://www.magentech.com
-------------------------------------------------------------------------*/
namespace Sm\MegaMenu\Block\Adminhtml\MenuItems\Edit;

use Magento\Framework\Json\EncoderInterface;
use Magento\Backend\Model\Auth\Session;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Translate\InlineInterface;

class Tabs extends \Magento\Backend\Block\Widget\Tabs
{
	const BASIC_TAB_GROUP_CODE = 'basic';

	/**
	 * @var InlineInterface
	 */
	protected $_translateInline;

	public function __construct(
		Context $context,
		Session $authSession,
		EncoderInterface $jsonEncoder,
		InlineInterface $translateInline,
		array $data = []
	){
		$this->_translateInline = $translateInline;
		parent::__construct($context, $jsonEncoder, $authSession, $data);
	}

	protected function _construct()
	{
		parent::_construct();
		$this->setId('menuitems_tabs');
		$this->setDestElementId('edit_form');
		$this->setTitle("<i class='fa fa-qrcode'></i>".__('Mega Menu'));
		if ($tab = $this->getRequest()->getParam('activeTab'))
			$this->_activeTab = $tab;
		else
			$this->_activeTab = 'menuitems';
	}

	protected function _translateHtml($html)
	{
		$this->_translateInline->processResponseBody($html);
		return $html;
	}

	protected function _prepareLayout()
	{
////		if ($this->getChildBlock('menuitems_form')) {
////			$this->addTab('menuitems_form', 'menuitems_form');
////			$this->getChildBlock('menuitems_form')->setGroupCode(self::BASIC_TAB_GROUP_CODE);
////		}

		$this->addTab(
			'menugroup',
			[
				'label' => __('Menu Group'),
				'title' => __('Menu Group'),
				'url' => $this->getUrl('*/menugroup/newaction',
					[
						'id' => $this->getRequest()->getParam('gid')
					]),
				'group_code' => self::BASIC_TAB_GROUP_CODE
			]
		);

		$this->addTab(
			'menuitems',
			[
				'label' => __('Menu Items'),
				'title' => __('Menu Items'),
				'content' => $this->_getTabHtml('\Form'),
				'group_code' => self::BASIC_TAB_GROUP_CODE
			]
		);

		return parent::_prepareLayout();
	}

	private function _getTabHtml($tab)
	{
		return $this->getLayout()->createBlock('\Sm\MegaMenu\Block\Adminhtml\MenuItems\Edit\Tab' . $tab )->toHtml();
	}
}