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
8 
10 
17 class Edit extends \Magento\Backend\Block\Widget\Form implements \Magento\Backend\Block\Widget\Tab\TabInterface
18 {
22  protected $_template = 'Magento_User::role/edit.phtml';
23 
29  protected $_rootResource;
30 
37 
43  protected $_aclRetriever;
44 
51 
55  protected $_integrationData;
56 
63  protected $coreRegistry = null;
64 
74  public function __construct(
75  \Magento\Backend\Block\Template\Context $context,
76  \Magento\Authorization\Model\Acl\AclRetriever $aclRetriever,
77  \Magento\Framework\Acl\RootResource $rootResource,
78  \Magento\Authorization\Model\ResourceModel\Rules\CollectionFactory $rulesCollectionFactory,
79  \Magento\Framework\Acl\AclResource\ProviderInterface $aclResourceProvider,
80  \Magento\Integration\Helper\Data $integrationData,
81  array $data = []
82  ) {
83  $this->_aclRetriever = $aclRetriever;
84  $this->_rootResource = $rootResource;
85  $this->_rulesCollectionFactory = $rulesCollectionFactory;
86  $this->_aclResourceProvider = $aclResourceProvider;
87  $this->_integrationData = $integrationData;
88  parent::__construct($context, $data);
89  }
90 
99  public function setCoreRegistry(\Magento\Framework\Registry $coreRegistry)
100  {
101  $this->coreRegistry = $coreRegistry;
102  }
103 
111  public function getCoreRegistry()
112  {
113  if (!($this->coreRegistry instanceof \Magento\Framework\Registry)) {
114  return \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Framework\Registry::class);
115  } else {
116  return $this->coreRegistry;
117  }
118  }
119 
125  public function getTabLabel()
126  {
127  return __('Role Resources');
128  }
129 
135  public function getTabTitle()
136  {
137  return $this->getTabLabel();
138  }
139 
145  public function canShowTab()
146  {
147  return true;
148  }
149 
155  public function isHidden()
156  {
157  return false;
158  }
159 
165  public function isEverythingAllowed()
166  {
167  $selectedResources = $this->getSelectedResources();
168  $id = $this->_rootResource->getId();
169  return in_array($id, $selectedResources);
170  }
171 
178  public function getSelectedResources()
179  {
180  $selectedResources = $this->getData('selected_resources');
181  if (empty($selectedResources)) {
182  $allResource = $this->getCoreRegistry()->registry(SaveRole::RESOURCE_ALL_FORM_DATA_SESSION_KEY);
183  if ($allResource) {
184  $selectedResources = [$this->_rootResource->getId()];
185  } else {
186  $selectedResources = $this->getCoreRegistry()->registry(SaveRole::RESOURCE_FORM_DATA_SESSION_KEY);
187  }
188 
189  if (null === $selectedResources) {
190  $rid = $this->_request->getParam('rid', false);
191  $selectedResources = $this->_aclRetriever->getAllowedResourcesByRole($rid);
192  }
193 
194  $this->setData('selected_resources', $selectedResources);
195  }
196  return $selectedResources;
197  }
198 
204  public function getTree()
205  {
206  return $this->_integrationData->mapResources($this->getAclResources());
207  }
208 
214  private function getAclResources()
215  {
216  $resources = $this->_aclResourceProvider->getAclResources();
217  $configResource = array_filter(
218  $resources,
219  function ($node) {
220  return isset($node['id'])
221  && $node['id'] == 'Magento_Backend::admin';
222  }
223  );
225  return isset($configResource['children']) ? $configResource['children'] : [];
226  }
227 }
getData($key='', $index=null)
Definition: DataObject.php:119
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13
setCoreRegistry(\Magento\Framework\Registry $coreRegistry)
Definition: Edit.php:99
setData($key, $value=null)
Definition: DataObject.php:72
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Authorization\Model\Acl\AclRetriever $aclRetriever, \Magento\Framework\Acl\RootResource $rootResource, \Magento\Authorization\Model\ResourceModel\Rules\CollectionFactory $rulesCollectionFactory, \Magento\Framework\Acl\AclResource\ProviderInterface $aclResourceProvider, \Magento\Integration\Helper\Data $integrationData, array $data=[])
Definition: Edit.php:74