<?php
namespace Solwin\Verticalmenu\Controller\Adminhtml;

abstract class Menu extends \Magento\Backend\App\Action
{
    /**
     * Menu Factory
     * 
     * @var \Solwin\Verticalmenu\Model\MenuFactory
     */
    protected $menuFactory;

    /**
     * Core registry
     * 
     * @var \Magento\Framework\Registry
     */
    protected $coreRegistry;

    /**
     * constructor
     * 
     * @param \Solwin\Verticalmenu\Model\MenuFactory $menuFactory
     * @param \Magento\Framework\Registry $coreRegistry
     * @param \Magento\Backend\App\Action\Context $context
     */
    public function __construct(
        \Solwin\Verticalmenu\Model\MenuFactory $menuFactory,
        \Magento\Framework\Registry $coreRegistry,
        \Magento\Backend\App\Action\Context $context
    ) {
        $this->menuFactory           = $menuFactory;
        $this->coreRegistry          = $coreRegistry;
        parent::__construct($context);
    }

    /**
     * Init Menu
     *
     * @return \Solwin\Verticalmenu\Model\Menu
     */
    protected function initMenu()
    {
        $menuId  = (int) $this->getRequest()->getParam('menu_id');
        /** @var \Solwin\Verticalmenu\Model\Menu $menu */
        $menu    = $this->menuFactory->create();
        if ($menuId) {
            $menu->load($menuId);
        }
        $this->coreRegistry->register('solwin_verticalmenu_menu', $menu);
        return $menu;
    }
}
