Skip to content

Commit 0e20896

Browse files
authored
Merge pull request #9 from landofcoder/feature2-1
Feature2 1
2 parents e05df06 + 3445c47 commit 0e20896

File tree

27 files changed

+1116
-74
lines changed

27 files changed

+1116
-74
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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\Edit;
7+
8+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
9+
10+
/**
11+
* Class BackButton
12+
*/
13+
class BackButton extends GenericButton implements ButtonProviderInterface
14+
{
15+
/**
16+
* @return array
17+
*/
18+
public function getButtonData()
19+
{
20+
return [
21+
'label' => __('Back'),
22+
'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()),
23+
'class' => 'back',
24+
'sort_order' => 10
25+
];
26+
}
27+
28+
/**
29+
* Get URL for back (reset) button
30+
*
31+
* @return string
32+
*/
33+
public function getBackUrl()
34+
{
35+
return $this->getUrl('*/*/');
36+
}
37+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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\Edit;
7+
8+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
9+
10+
/**
11+
* Class DeleteButton
12+
*/
13+
class DeleteButton extends GenericButton implements ButtonProviderInterface
14+
{
15+
/**
16+
* @inheritDoc
17+
*/
18+
public function getButtonData()
19+
{
20+
$data = [];
21+
if ($this->getBlockId()) {
22+
$data = [
23+
'label' => __('Delete Tag'),
24+
'class' => 'delete',
25+
'on_click' => 'deleteConfirm(\'' . __(
26+
'Are you sure you want to do this?'
27+
) . '\', \'' . $this->getDeleteUrl() . '\', {"data": {}})',
28+
'sort_order' => 20,
29+
];
30+
}
31+
return $data;
32+
}
33+
34+
/**
35+
* URL to send delete requests to.
36+
*
37+
* @return string
38+
*/
39+
public function getDeleteUrl()
40+
{
41+
return $this->getUrl('*/*/delete', ['tag_id' => $this->getBlockId()]);
42+
}
43+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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\Edit;
7+
8+
use Magento\Backend\Block\Widget\Context;
9+
use Magento\Cms\Api\BlockRepositoryInterface;
10+
use Magento\Framework\Exception\NoSuchEntityException;
11+
12+
/**
13+
* Class GenericButton
14+
*/
15+
class GenericButton
16+
{
17+
/**
18+
* @var Context
19+
*/
20+
protected $context;
21+
22+
/**
23+
* @var BlockRepositoryInterface
24+
*/
25+
protected $blockRepository;
26+
27+
/**
28+
* @param Context $context
29+
* @param BlockRepositoryInterface $blockRepository
30+
*/
31+
public function __construct(
32+
Context $context,
33+
BlockRepositoryInterface $blockRepository
34+
) {
35+
$this->context = $context;
36+
$this->blockRepository = $blockRepository;
37+
}
38+
39+
/**
40+
* Return CMS block ID
41+
*
42+
* @return int|null
43+
*/
44+
public function getBlockId()
45+
{
46+
try {
47+
return $this->blockRepository->getById(
48+
$this->context->getRequest()->getParam('tag_id')
49+
)->getId();
50+
} catch (NoSuchEntityException $e) {
51+
}
52+
return null;
53+
}
54+
55+
/**
56+
* Generate url by route and parameters
57+
*
58+
* @param string $route
59+
* @param array $params
60+
* @return string
61+
*/
62+
public function getUrl($route = '', $params = [])
63+
{
64+
return $this->context->getUrlBuilder()->getUrl($route, $params);
65+
}
66+
}
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\Block\Adminhtml\Tags\Edit;
7+
8+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
9+
use Magento\Ui\Component\Control\Container;
10+
11+
/**
12+
* Class SaveButton
13+
* @package Lof\ProductTags\Block\Adminhtml\Tags\Edit
14+
*/
15+
class SaveButton extends GenericButton implements ButtonProviderInterface
16+
{
17+
/**
18+
* @return array
19+
*/
20+
public function getButtonData()
21+
{
22+
return [
23+
'label' => __('Save'),
24+
'class' => 'save primary',
25+
'data_attribute' => [
26+
'mage-init' => [
27+
'buttonAdapter' => [
28+
'actions' => [
29+
[
30+
'targetName' => 'cms_block_form.cms_block_form',
31+
'actionName' => 'save',
32+
'params' => [
33+
true,
34+
[
35+
'back' => 'continue'
36+
]
37+
]
38+
]
39+
]
40+
]
41+
]
42+
],
43+
'class_name' => Container::SPLIT_BUTTON,
44+
'options' => $this->getOptions(),
45+
];
46+
}
47+
48+
/**
49+
* Retrieve options
50+
*
51+
* @return array
52+
*/
53+
private function getOptions()
54+
{
55+
$options = [
56+
[
57+
'label' => __('Save & Duplicate'),
58+
'id_hard' => 'save_and_duplicate',
59+
'data_attribute' => [
60+
'mage-init' => [
61+
'buttonAdapter' => [
62+
'actions' => [
63+
[
64+
'targetName' => 'cms_block_form.cms_block_form',
65+
'actionName' => 'save',
66+
'params' => [
67+
true,
68+
[
69+
'back' => 'duplicate'
70+
]
71+
]
72+
]
73+
]
74+
]
75+
]
76+
]
77+
],
78+
[
79+
'id_hard' => 'save_and_close',
80+
'label' => __('Save & Close'),
81+
'data_attribute' => [
82+
'mage-init' => [
83+
'buttonAdapter' => [
84+
'actions' => [
85+
[
86+
'targetName' => 'producttags_tag_form.producttags_tag_form',
87+
'actionName' => 'save',
88+
'params' => [
89+
true,
90+
[
91+
'back' => 'close'
92+
]
93+
]
94+
]
95+
]
96+
]
97+
]
98+
]
99+
]
100+
];
101+
102+
return $options;
103+
}
104+
}
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.

0 commit comments

Comments
 (0)