Skip to content

Commit e0e0b1d

Browse files
committed
updated grid form ui component
1 parent c3e5574 commit e0e0b1d

File tree

21 files changed

+796
-74
lines changed

21 files changed

+796
-74
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Lof\ProductTags\Block\Adminhtml\Tags\Grid\Renderer\Action;
7+
8+
/**
9+
* Url builder class used to compose dynamic urls.
10+
*/
11+
class UrlBuilder
12+
{
13+
/**
14+
* @var \Magento\Framework\UrlInterface
15+
*/
16+
protected $frontendUrlBuilder;
17+
18+
/**
19+
* @param \Magento\Framework\UrlInterface $frontendUrlBuilder
20+
*/
21+
public function __construct(\Magento\Framework\UrlInterface $frontendUrlBuilder)
22+
{
23+
$this->frontendUrlBuilder = $frontendUrlBuilder;
24+
}
25+
26+
/**
27+
* Get action url
28+
*
29+
* @param string $routePath
30+
* @param string $scope
31+
* @param string $store
32+
* @return string
33+
*/
34+
public function getUrl($routePath, $scope, $store)
35+
{
36+
if ($scope) {
37+
$this->frontendUrlBuilder->setScope($scope);
38+
$href = $this->frontendUrlBuilder->getUrl(
39+
$routePath,
40+
[
41+
'_current' => false,
42+
'_nosid' => true,
43+
'_query' => [\Magento\Store\Model\StoreManagerInterface::PARAM_NAME => $store]
44+
]
45+
);
46+
} else {
47+
$href = $this->frontendUrlBuilder->getUrl(
48+
$routePath,
49+
[
50+
'_current' => false,
51+
'_nosid' => true
52+
]
53+
);
54+
}
55+
56+
return $href;
57+
}
58+
}

Controller/Adminhtml/Tag/Delete.php

Whitespace-only changes.

Controller/Adminhtml/Tag/Edit.php

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Lof\ProductTags\Controller\Adminhtml\Tag;
7+
8+
use Magento\Framework\App\Action\HttpGetActionInterface;
9+
use Magento\Backend\App\Action;
10+
11+
/**
12+
* Edit CMS page action.
13+
*/
14+
class Edit extends \Magento\Backend\App\Action implements HttpGetActionInterface
15+
{
16+
/**
17+
* Authorization level of a basic admin session
18+
*
19+
* @see _isAllowed()
20+
*/
21+
const ADMIN_RESOURCE = 'Lof_ProductTags::Tag_edit';
22+
23+
/**
24+
* Core registry
25+
*
26+
* @var \Magento\Framework\Registry
27+
*/
28+
protected $_coreRegistry;
29+
30+
/**
31+
* @var \Magento\Framework\View\Result\PageFactory
32+
*/
33+
protected $resultPageFactory;
34+
35+
/**
36+
* @param Action\Context $context
37+
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
38+
* @param \Magento\Framework\Registry $registry
39+
*/
40+
public function __construct(
41+
Action\Context $context,
42+
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
43+
\Magento\Framework\Registry $registry
44+
) {
45+
$this->resultPageFactory = $resultPageFactory;
46+
$this->_coreRegistry = $registry;
47+
parent::__construct($context);
48+
}
49+
50+
/**
51+
* Init actions
52+
*
53+
* @return \Magento\Backend\Model\View\Result\Page
54+
*/
55+
protected function _initAction()
56+
{
57+
// load layout, set active menu and breadcrumbs
58+
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
59+
$resultPage = $this->resultPageFactory->create();
60+
$resultPage->setActiveMenu('Lof_ProductTags::producttags')
61+
->addBreadcrumb(__('Product Tags'), __('Product Tags'))
62+
->addBreadcrumb(__('Manage Tags'), __('Manage Tags'));
63+
return $resultPage;
64+
}
65+
66+
/**
67+
* Edit CMS page
68+
*
69+
* @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect
70+
* @SuppressWarnings(PHPMD.NPathComplexity)
71+
*/
72+
public function execute()
73+
{
74+
// 1. Get ID and create model
75+
$id = $this->getRequest()->getParam('tag_id');
76+
$model = $this->_objectManager->create(\Lof\ProductTags\Model\Tag::class);
77+
78+
// 2. Initial checking
79+
if ($id) {
80+
$model->load($id);
81+
if (!$model->getId()) {
82+
$this->messageManager->addErrorMessage(__('This tag no longer exists.'));
83+
/** \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
84+
$resultRedirect = $this->resultRedirectFactory->create();
85+
return $resultRedirect->setPath('*/*/');
86+
}
87+
}
88+
89+
$this->_coreRegistry->register('product_tag', $model);
90+
91+
// 5. Build edit form
92+
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
93+
$resultPage = $this->_initAction();
94+
$resultPage->addBreadcrumb(
95+
$id ? __('Edit Tag') : __('New Tag'),
96+
$id ? __('Edit Tag') : __('New Tag')
97+
);
98+
$resultPage->getConfig()->getTitle()->prepend(__('Tags'));
99+
$resultPage->getConfig()->getTitle()
100+
->prepend($model->getId() ? $model->getTitle() : __('New Tag'));
101+
102+
return $resultPage;
103+
}
104+
}

Controller/Adminhtml/Tag/Index.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525

2626
class Index extends \Magento\Backend\App\Action
2727
{
28+
/**
29+
* Authorization level of a basic admin session
30+
*
31+
* @see _isAllowed()
32+
*/
33+
const ADMIN_RESOURCE = 'Lof_ProductTags::Tag';
2834

2935
protected $resultPageFactory = false;
3036

Controller/Adminhtml/Tag/MassDelete.php

Whitespace-only changes.

Controller/Adminhtml/Tag/MassDisable.php

Whitespace-only changes.

Controller/Adminhtml/Tag/MassEnable.php

Whitespace-only changes.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Lof\ProductTags\Controller\Adminhtml\Tag;
8+
9+
use Magento\Framework\App\Action\HttpGetActionInterface;
10+
11+
/**
12+
* Create CMS page action.
13+
*/
14+
class NewAction extends \Magento\Backend\App\Action implements HttpGetActionInterface
15+
{
16+
/**
17+
* Authorization level of a basic admin session
18+
*
19+
* @see _isAllowed()
20+
*/
21+
const ADMIN_RESOURCE = 'Lof_ProductTags::Tag_add';
22+
23+
/**
24+
* @var \Magento\Backend\Model\View\Result\Forward
25+
*/
26+
protected $resultForwardFactory;
27+
28+
/**
29+
* @param \Magento\Backend\App\Action\Context $context
30+
* @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
31+
*/
32+
public function __construct(
33+
\Magento\Backend\App\Action\Context $context,
34+
\Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
35+
) {
36+
$this->resultForwardFactory = $resultForwardFactory;
37+
parent::__construct($context);
38+
}
39+
40+
/**
41+
* Forward to edit
42+
*
43+
* @return \Magento\Backend\Model\View\Result\Forward
44+
*/
45+
public function execute()
46+
{
47+
/** @var \Magento\Backend\Model\View\Result\Forward $resultForward */
48+
$resultForward = $this->resultForwardFactory->create();
49+
return $resultForward->forward('edit');
50+
}
51+
}

Controller/Adminhtml/Tag/Save.php

Whitespace-only changes.

Controller/Adminhtml/Tags/Index.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)