Edit   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 98
c 0
b 0
f 0
wmc 8
lcom 1
cbo 0
ccs 0
cts 57
cp 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A _construct() 0 26 2
A getHeaderText() 0 13 2
A isAllowed() 0 4 1
A _getSaveAndContinueUrl() 0 4 1
A getBackUrl() 0 4 1
1
<?php
2
/**
3
 * File: Edit.php
4
 *
5
 * @author      Maciej Sławik <[email protected]>
6
 * Github:      https://github.com/maciejslawik
7
 */
8
9
namespace MSlwk\ICatalogue\Block\Adminhtml\Catalogue;
10
11
use Magento\Backend\Block\Widget\Context;
12
use Magento\Backend\Block\Widget\Form\Container;
13
use Magento\Framework\Phrase;
14
use Magento\Framework\Registry;
15
16
/**
17
 * Class Edit
18
 *
19
 * @package MSlwk\ICatalogue\Block\Adminhtml\Catalogue
20
 */
21
class Edit extends Container
22
{
23
    /**
24
     * Core registry
25
     *
26
     * @var Registry
27
     */
28
    protected $coreRegistry = null;
29
30
    /**
31
     * @param Context $context
32
     * @param Registry $registry
33
     * @param array $data
34
     */
35
    public function __construct(
36
        Context $context,
37
        Registry $registry,
38
        array $data = []
39
    ) {
40
        $this->coreRegistry = $registry;
41
        parent::__construct($context, $data);
42
    }
43
44
    /**
45
     * Department edit block
46
     *
47
     * @return void
48
     */
49
    protected function _construct()
50
    {
51
        $this->_objectId = 'id';
52
        $this->_blockGroup = 'MSlwk_ICatalogue';
53
        $this->_controller = 'adminhtml_catalogue';
54
55
        parent::_construct();
56
57
        if ($this->isAllowed()) {
58
            $this->buttonList->update('save', 'label', __('Save Catalogue'));
59
            $this->buttonList->add(
60
                'saveandcontinue',
61
                [
62
                    'label' => __('Save and Continue Edit'),
63
                    'class' => 'save',
64
                    'data_attribute' => [
65
                        'mage-init' => [
66
                            'button' => ['event' => 'saveAndContinueEdit', 'target' => '#edit_form'],
67
                        ],
68
                    ]
69
                ]
70
            );
71
        } else {
72
            $this->buttonList->remove('save');
73
        }
74
    }
75
76
    /**
77
     * @return Phrase
78
     */
79
    public function getHeaderText()
80
    {
81
        if ($this->coreRegistry->registry('mslwk_icatalogue_catalogue')->getId()) {
82
            return __(
83
                "Edit catalogue '%1'",
84
                $this->escapeHtml(
85
                    $this->coreRegistry->registry('mslwk_icatalogue_catalogue')->getName()
86
                )
87
            );
88
        } else {
89
            return __('New Catalogue');
90
        }
91
    }
92
93
    /**
94
     * Check permission for passed action
95
     *
96
     * @return bool
97
     */
98
    protected function isAllowed()
99
    {
100
        return $this->_authorization->isAllowed('MSlwk_ICatalogue::catalogue_manage');
101
    }
102
103
    /**
104
     * @return string
105
     */
106
    protected function _getSaveAndContinueUrl()
107
    {
108
        return $this->getUrl('icatalogue/catalogue/save', ['_current' => true, 'back' => 'edit', 'active_tab' => '']);
109
    }
110
111
    /**
112
     * @return string
113
     */
114
    public function getBackUrl()
115
    {
116
        return $this->getUrl('*/*/grid');
117
    }
118
}