Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Edit.php
Go to the documentation of this file.
1 <?php
7 
10 
17 class Edit extends \Magento\Backend\Block\Widget\Form\Container
18 {
24  protected $_coreRegistry = null;
25 
29  private $serializer;
30 
37  public function __construct(
38  \Magento\Backend\Block\Widget\Context $context,
39  \Magento\Framework\Registry $registry,
40  array $data = [],
41  SerializerInterface $serializer = null
42  ) {
43  $this->_coreRegistry = $registry;
44  $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
45  parent::__construct($context, $data);
46  }
47 
53  protected function _construct()
54  {
55  switch ($this->_coreRegistry->registry('store_type')) {
56  case 'website':
57  $this->_objectId = 'website_id';
58  $saveLabel = __('Save Web Site');
59  $deleteLabel = __('Delete Web Site');
60  $deleteUrl = $this->getUrl(
61  '*/*/deleteWebsite',
62  ['item_id' => $this->_coreRegistry->registry('store_data')->getId()]
63  );
64  break;
65  case 'group':
66  $this->_objectId = 'group_id';
67  $saveLabel = __('Save Store');
68  $deleteLabel = __('Delete Store');
69  $deleteUrl = $this->getUrl(
70  '*/*/deleteGroup',
71  ['item_id' => $this->_coreRegistry->registry('store_data')->getId()]
72  );
73  break;
74  case 'store':
75  $this->_objectId = 'store_id';
76  $saveLabel = __('Save Store View');
77  $deleteLabel = __('Delete Store View');
78  $deleteUrl = $this->getUrl(
79  '*/*/deleteStore',
80  ['item_id' => $this->_coreRegistry->registry('store_data')->getId()]
81  );
82  break;
83  default:
84  $saveLabel = '';
85  $deleteLabel = '';
86  $deleteUrl = '';
87  }
88  $this->_blockGroup = 'Magento_Backend';
89  $this->_controller = 'system_store';
90 
91  parent::_construct();
92 
93  $this->buttonList->update('save', 'label', $saveLabel);
94  $this->buttonList->update('delete', 'label', $deleteLabel);
95  $this->buttonList->update('delete', 'onclick', 'setLocation(\'' . $deleteUrl . '\');');
96 
97  if (!$this->_coreRegistry->registry('store_data')) {
98  return;
99  }
100 
101  if (!$this->_coreRegistry->registry('store_data')->isCanDelete()) {
102  $this->buttonList->remove('delete');
103  }
104  if ($this->_coreRegistry->registry('store_data')->isReadOnly()) {
105  $this->buttonList->remove('save');
106  $this->buttonList->remove('reset');
107  }
108  }
109 
115  public function getHeaderText()
116  {
117  switch ($this->_coreRegistry->registry('store_type')) {
118  case 'website':
119  $editLabel = __('Edit Web Site');
120  $addLabel = __('New Web Site');
121  break;
122  case 'group':
123  $editLabel = __('Edit Store');
124  $addLabel = __('New Store');
125  break;
126  case 'store':
127  $editLabel = __('Edit Store View');
128  $addLabel = __('New Store View');
129  break;
130  }
131 
132  return $this->_coreRegistry->registry('store_action') == 'add' ? $addLabel : $editLabel;
133  }
134 
140  protected function _buildFormClassName()
141  {
142  return parent::_buildFormClassName() . '\\' . ucwords($this->_coreRegistry->registry('store_type'));
143  }
144 
151  public function getStoreData()
152  {
153  return $this->serializer->serialize($this->_coreRegistry->registry('store_data')->getData());
154  }
155 }
__construct(\Magento\Backend\Block\Widget\Context $context, \Magento\Framework\Registry $registry, array $data=[], SerializerInterface $serializer=null)
Definition: Edit.php:37
__()
Definition: __.php:13