-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
58 changed files
with
3,272 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace UpSage\Menu\Api\Data; | ||
|
||
interface MenuInterface { | ||
|
||
const MENU_ID = 'menu_id'; | ||
const IDENTIFIER = 'identifier'; | ||
const TITLE = 'title'; | ||
const CONTENT = 'content'; | ||
const CREATION_TIME = 'creation_time'; | ||
const UPDATE_TIME = 'update_time'; | ||
const IS_ACTIVE = 'is_active'; | ||
|
||
public function getId(); | ||
|
||
public function getIdentifier(); | ||
|
||
public function getTitle(); | ||
|
||
public function getContent(); | ||
|
||
public function getCreationTime(); | ||
|
||
public function getUpdateTime(); | ||
|
||
public function isActive(); | ||
|
||
public function setId($id); | ||
|
||
public function setIdentifier($identifier); | ||
|
||
public function setTitle($title); | ||
|
||
public function setContent($content); | ||
|
||
public function setCreationTime($creationTime); | ||
|
||
public function setUpdateTime($updateTime); | ||
|
||
public function setIsActive($isActive); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace UpSage\Menu\Api\Data; | ||
|
||
use Magento\Framework\Api\SearchResultsInterface; | ||
|
||
interface MenuSearchResultsInterface extends SearchResultsInterface { | ||
public function getItems(); | ||
public function setItems(array $items); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace UpSage\Menu\Api; | ||
|
||
interface GetMenuByIdentifierInterface { | ||
public function execute(string $identifier, int $storeId) : \UpSage\Menu\Api\Data\MenuInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace UpSage\Menu\Api; | ||
|
||
interface MenuRepositoryInterface { | ||
|
||
public function save(Data\MenuInterface $menu); | ||
|
||
public function getById($menuId); | ||
|
||
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria); | ||
|
||
public function delete(Data\MenuInterface $menu); | ||
|
||
public function deleteById($menuId); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace UpSage\Menu\Block\Adminhtml; | ||
|
||
class Menu extends \Magento\Backend\Block\Widget\Grid\Container { | ||
|
||
protected function _construct() { | ||
$this->_blockGroup = 'UpSage_Menu'; | ||
$this->_controller = 'adminhtml_menu'; | ||
$this->_headerText = __('Menus'); | ||
$this->_addButtonLabel = __('Add New Menu'); | ||
parent::_construct(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace UpSage\Menu\Block\Adminhtml\Menu\Edit; | ||
|
||
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface; | ||
|
||
class BackButton extends GenericButton implements ButtonProviderInterface { | ||
|
||
public function getButtonData() { | ||
return [ | ||
'label' => __('Back'), | ||
'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()), | ||
'class' => 'back', | ||
'sort_order' => 10 | ||
]; | ||
} | ||
|
||
public function getBackUrl() { | ||
return $this->getUrl('*/*/'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace UpSage\Menu\Block\Adminhtml\Menu\Edit; | ||
|
||
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface; | ||
|
||
class DeleteButton extends GenericButton implements ButtonProviderInterface { | ||
|
||
public function getButtonData() { | ||
$data = []; | ||
if($this->getMenuId()) { | ||
$data = [ | ||
'label' => __('Delete Menu'), | ||
'class' => 'delete', | ||
'on_click' => 'deleteConfirm(\'' . __('Are you sure you want to do this?') . '\', \'' . $this->getDeleteUrl() . '\', {"data": {}})', | ||
'sort_order' => 20, | ||
]; | ||
} | ||
return $data; | ||
} | ||
|
||
public function getDeleteUrl() { | ||
return $this->getUrl('*/*/delete', ['menu_id' => $this->getMenuId()]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace UpSage\Menu\Block\Adminhtml\Menu\Edit; | ||
|
||
use Magento\Backend\Block\Widget\Context; | ||
use UpSage\Menu\Api\MenuRepositoryInterface; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
|
||
class GenericButton { | ||
|
||
protected $context; | ||
|
||
protected $menuRepository; | ||
|
||
public function __construct( | ||
Context $context, | ||
MenuRepositoryInterface $menuRepository | ||
) { | ||
$this->context = $context; | ||
$this->menuRepository = $menuRepository; | ||
} | ||
|
||
public function getMenuId() { | ||
try { | ||
return $this->menuRepository->getById( | ||
$this->context->getRequest()->getParam('menu_id') | ||
)->getId(); | ||
} catch (NoSuchEntityException $e) {} | ||
return null; | ||
} | ||
|
||
public function getUrl($route = '', $params = []) { | ||
return $this->context->getUrlBuilder()->getUrl($route, $params); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace UpSage\Menu\Block\Adminhtml\Menu\Edit; | ||
|
||
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface; | ||
use Magento\Ui\Component\Control\Container; | ||
|
||
class SaveButton extends GenericButton implements ButtonProviderInterface { | ||
|
||
public function getButtonData() { | ||
return [ | ||
'label' => __('Save'), | ||
'class' => 'save primary', | ||
'data_attribute' => [ | ||
'mage-init' => [ | ||
'buttonAdapter' => [ | ||
'actions' => [ | ||
[ | ||
'targetName' => 'upsage_menu_form.upsage_menu_form', | ||
'actionName' => 'save', | ||
'params' => [ | ||
true, | ||
['back' => 'continue'] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
], | ||
'class_name' => Container::SPLIT_BUTTON, | ||
'options' => $this->getOptions(), | ||
'dropdown_button_aria_label' => __('Save options'), | ||
]; | ||
} | ||
|
||
private function getOptions() { | ||
$options = [ | ||
[ | ||
'label' => __('Save & Duplicate'), | ||
'id_hard' => 'save_and_duplicate', | ||
'data_attribute' => [ | ||
'mage-init' => [ | ||
'buttonAdapter' => [ | ||
'actions' => [ | ||
[ | ||
'targetName' => 'upsage_menu_form.upsage_menu_form', | ||
'actionName' => 'save', | ||
'params' => [ | ||
true, | ||
['back' => 'duplicate'] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
], | ||
[ | ||
'id_hard' => 'save_and_close', | ||
'label' => __('Save & Close'), | ||
'data_attribute' => [ | ||
'mage-init' => [ | ||
'buttonAdapter' => [ | ||
'actions' => [ | ||
[ | ||
'targetName' => 'upsage_menu_form.upsage_menu_form', | ||
'actionName' => 'save', | ||
'params' => [ | ||
true, | ||
['back' => 'close'] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
]; | ||
return $options; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
namespace UpSage\Menu\Block\Adminhtml\Menu\Widget; | ||
|
||
class Chooser extends \Magento\Backend\Block\Widget\Grid\Extended { | ||
|
||
protected $_menuFactory; | ||
|
||
protected $_collectionFactory; | ||
|
||
public function __construct( | ||
\Magento\Backend\Block\Template\Context $context, | ||
\Magento\Backend\Helper\Data $backendHelper, | ||
\UpSage\Menu\Model\MenuFactory $menuFactory, | ||
\UpSage\Menu\Model\ResourceModel\Menu\CollectionFactory $collectionFactory, | ||
array $data = [] | ||
) { | ||
$this->_menuFactory = $menuFactory; | ||
$this->_collectionFactory = $collectionFactory; | ||
parent::__construct($context, $backendHelper, $data); | ||
} | ||
|
||
protected function _construct() { | ||
parent::_construct(); | ||
$this->setDefaultSort('menu_identifier'); | ||
$this->setDefaultDir('ASC'); | ||
$this->setUseAjax(true); | ||
$this->setDefaultFilter(['chooser_is_active' => '1']); | ||
} | ||
|
||
public function prepareElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) { | ||
$uniqId = $this->mathRandom->getUniqueHash($element->getId()); | ||
$sourceUrl = $this->getUrl('upsage/menu_widget/chooser', ['uniq_id' => $uniqId]); | ||
$chooser = $this->getLayout()->createBlock( | ||
\Magento\Widget\Block\Adminhtml\Widget\Chooser::class | ||
)->setElement( | ||
$element | ||
)->setConfig( | ||
$this->getConfig() | ||
)->setFieldsetId( | ||
$this->getFieldsetId() | ||
)->setSourceUrl( | ||
$sourceUrl | ||
)->setUniqId( | ||
$uniqId | ||
); | ||
|
||
if($element->getValue()) { | ||
$menu = $this->_menuFactory->create()->load($element->getValue()); | ||
if($menu->getId()) { | ||
$chooser->setLabel($this->escapeHtml($menu->getTitle())); | ||
} | ||
} | ||
|
||
$element->setData('after_element_html', $chooser->toHtml()); | ||
return $element; | ||
} | ||
|
||
public function getRowClickCallback() { | ||
$chooserJsObject = $this->getId(); | ||
$js = ' | ||
function (grid, event) { | ||
var trElement = Event.findElement(event, "tr"); | ||
var menuId = trElement.down("td").innerHTML.replace(/^\s+|\s+$/g,""); | ||
var menuTitle = trElement.down("td").next().innerHTML;' . | ||
$chooserJsObject . '.setElementValue(menuId); ' . | ||
$chooserJsObject . '.setElementLabel(menuTitle); ' . | ||
$chooserJsObject . '.close(); | ||
} | ||
'; | ||
return $js; | ||
} | ||
|
||
protected function _prepareCollection() { | ||
$this->setCollection($this->_collectionFactory->create()); | ||
return parent::_prepareCollection(); | ||
} | ||
|
||
protected function _prepareColumns() { | ||
|
||
$this->addColumn( | ||
'chooser_id', | ||
['header' => __('ID'), 'align' => 'right', 'index' => 'menu_id', 'width' => 50] | ||
); | ||
|
||
$this->addColumn('chooser_title', ['header' => __('Title'), 'align' => 'left', 'index' => 'title']); | ||
|
||
$this->addColumn( | ||
'chooser_identifier', | ||
['header' => __('Identifier'), 'align' => 'left', 'index' => 'identifier'] | ||
); | ||
|
||
$this->addColumn( | ||
'chooser_is_active', | ||
[ | ||
'header' => __('Status'), | ||
'index' => 'is_active', | ||
'type' => 'options', | ||
'options' => [0 => __('Disabled'), 1 => __('Enabled')] | ||
] | ||
); | ||
|
||
return parent::_prepareColumns(); | ||
|
||
} | ||
|
||
public function getGridUrl() { | ||
return $this->getUrl('upsage/menu_widget/chooser', ['_current' => true]); | ||
} | ||
|
||
} |
Oops, something went wrong.