Skip to content

Commit de6fdd9

Browse files
committed
Added admin form buttons
1 parent 080f694 commit de6fdd9

File tree

10 files changed

+337
-1
lines changed

10 files changed

+337
-1
lines changed

Block/Adminhtml/Edit/BackButton.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*/
6+
7+
namespace Magefan\Community\Block\Adminhtml\Edit;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
11+
/**
12+
* Class BackButton
13+
*/
14+
class BackButton extends GenericButton implements ButtonProviderInterface
15+
{
16+
/**
17+
* @return array
18+
*/
19+
public function getButtonData()
20+
{
21+
return [
22+
'label' => __('Back'),
23+
'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()),
24+
'class' => 'back',
25+
'sort_order' => 10
26+
];
27+
}
28+
29+
/**
30+
* Get URL for back (reset) button
31+
*
32+
* @return string
33+
*/
34+
public function getBackUrl()
35+
{
36+
return $this->getUrl('*/*/');
37+
}
38+
}

Block/Adminhtml/Edit/CreateButton.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*/
6+
7+
namespace Magefan\Community\Block\Adminhtml\Edit;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
11+
/**
12+
* Button "Create"
13+
*/
14+
class CreateButton extends GenericButton implements ButtonProviderInterface
15+
{
16+
/**
17+
* @return array
18+
*/
19+
public function getButtonData()
20+
{
21+
return [
22+
'label' => __('Create'),
23+
'class' => 'save primary',
24+
'data_attribute' => [
25+
'mage-init' => ['button' => ['event' => 'save']],
26+
'form-role' => 'save',
27+
],
28+
'sort_order' => 10
29+
];
30+
}
31+
}

Block/Adminhtml/Edit/DeleteButton.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*/
6+
7+
namespace Magefan\Community\Block\Adminhtml\Edit;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
11+
/**
12+
* Class DeleteButton
13+
*/
14+
class DeleteButton extends GenericButton implements ButtonProviderInterface
15+
{
16+
17+
/**
18+
* @return array
19+
*/
20+
public function getButtonData()
21+
{
22+
$data = [];
23+
if ($this->getObjectId()) {
24+
$data = [
25+
'label' => __('Delete'),
26+
'class' => 'delete',
27+
'on_click' => 'deleteConfirm(\'' . __(
28+
'Are you sure you want to do this?'
29+
) . '\', \'' . $this->getDeleteUrl() . '\')',
30+
'sort_order' => 20,
31+
];
32+
}
33+
return $data;
34+
}
35+
36+
/**
37+
* @return string
38+
*/
39+
public function getDeleteUrl()
40+
{
41+
return $this->getUrl('*/*/delete', ['id' => $this->getObjectId()]);
42+
}
43+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*/
6+
7+
namespace Magefan\Community\Block\Adminhtml\Edit;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
11+
/**
12+
* Class DuplicateButton
13+
*/
14+
class DuplicateButton extends GenericButton implements ButtonProviderInterface
15+
{
16+
/**
17+
* @return array
18+
*/
19+
public function getButtonData()
20+
{
21+
$data = [];
22+
if ($this->getObjectId()) {
23+
$data = [
24+
'label' => __('Duplicate'),
25+
'class' => 'duplicate',
26+
'on_click' => 'window.location=\'' . $this->getDuplicateUrl() . '\'',
27+
'sort_order' => 40,
28+
];
29+
}
30+
return $data;
31+
}
32+
33+
/**
34+
* @return string
35+
*/
36+
public function getDuplicateUrl()
37+
{
38+
return $this->getUrl('*/*/duplicate', ['id' => $this->getObjectId()]);
39+
}
40+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*/
6+
7+
namespace Magefan\Community\Block\Adminhtml\Edit;
8+
9+
use Magento\Backend\Block\Widget\Context;
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+
* @param Context $context
24+
* @param BlockRepositoryInterface $blockRepository
25+
*/
26+
public function __construct(
27+
Context $context
28+
) {
29+
$this->context = $context;
30+
}
31+
32+
/**
33+
* Return CMS block ID
34+
*
35+
* @return int|null
36+
*/
37+
public function getObjectId()
38+
{
39+
return $this->context->getRequest()->getParam('id');
40+
}
41+
42+
/**
43+
* Generate url by route and parameters
44+
*
45+
* @param string $route
46+
* @param array $params
47+
* @return string
48+
*/
49+
public function getUrl($route = '', $params = [])
50+
{
51+
return $this->context->getUrlBuilder()->getUrl($route, $params);
52+
}
53+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*/
6+
7+
namespace Magefan\Community\Block\Adminhtml\Edit;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
11+
/**
12+
* Class PreviewButton
13+
*/
14+
class PreviewButton extends GenericButton implements ButtonProviderInterface
15+
{
16+
/**
17+
* @return array
18+
*/
19+
public function getButtonData()
20+
{
21+
$data = [];
22+
if ($this->getObjectId()) {
23+
$data = [
24+
'label' => __('Preview'),
25+
'class' => 'preview',
26+
'on_click' => 'window.open(\'' . $this->getPreviewUrl() . '\');',
27+
'sort_order' => 35,
28+
];
29+
}
30+
return $data;
31+
}
32+
33+
/**
34+
* @return string
35+
*/
36+
public function getPreviewUrl()
37+
{
38+
return $this->getUrl('*/*/preview', ['id' => $this->getObjectId()]);
39+
}
40+
}

Block/Adminhtml/Edit/ResetButton.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*/
6+
7+
namespace Magefan\Community\Block\Adminhtml\Edit;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
11+
/**
12+
* Class ResetButton
13+
*/
14+
class ResetButton implements ButtonProviderInterface
15+
{
16+
/**
17+
* @return array
18+
*/
19+
public function getButtonData()
20+
{
21+
return [
22+
'label' => __('Reset'),
23+
'class' => 'reset',
24+
'on_click' => 'location.reload();',
25+
'sort_order' => 30
26+
];
27+
}
28+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*/
6+
7+
namespace Magefan\Community\Block\Adminhtml\Edit;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
11+
/**
12+
* Class SaveAndContinueButton
13+
*/
14+
class SaveAndContinueButton extends GenericButton implements ButtonProviderInterface
15+
{
16+
17+
/**
18+
* @return array
19+
*/
20+
public function getButtonData()
21+
{
22+
return [
23+
'label' => __('Save and Continue Edit'),
24+
'class' => 'save',
25+
'data_attribute' => [
26+
'mage-init' => [
27+
'button' => ['event' => 'saveAndContinueEdit'],
28+
],
29+
],
30+
'sort_order' => 80,
31+
];
32+
}
33+
}

Block/Adminhtml/Edit/SaveButton.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*/
6+
7+
namespace Magefan\Community\Block\Adminhtml\Edit;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
11+
/**
12+
* Class SaveButton
13+
*/
14+
class SaveButton extends GenericButton implements ButtonProviderInterface
15+
{
16+
/**
17+
* @return array
18+
*/
19+
public function getButtonData()
20+
{
21+
return [
22+
'label' => __('Save'),
23+
'class' => 'save primary',
24+
'data_attribute' => [
25+
'mage-init' => ['button' => ['event' => 'save']],
26+
'form-role' => 'save',
27+
],
28+
'sort_order' => 90,
29+
];
30+
}
31+
}

Controller/Adminhtml/Actions.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ abstract class Actions extends \Magento\Backend\App\Action
8383

8484
/**
8585
* @param Action\Context $context
86-
* @param PostDataProcessor $dataProcessor
8786
* @param DataPersistorInterface $dataPersistor
8887
*/
8988
public function __construct(

0 commit comments

Comments
 (0)