Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DisableOutput.php
Go to the documentation of this file.
1 <?php
7 
21 class DisableOutput extends \Magento\Config\Block\System\Config\Form\Fieldset
22 {
27  protected $_dummyElement;
28 
33  protected $_fieldRenderer;
34 
39  protected $_values;
40 
45  protected $_moduleList;
46 
54  public function __construct(
55  \Magento\Backend\Block\Context $context,
56  \Magento\Backend\Model\Auth\Session $authSession,
57  \Magento\Framework\View\Helper\Js $jsHelper,
58  \Magento\Framework\Module\ModuleListInterface $moduleList,
59  array $data = []
60  ) {
61  parent::__construct($context, $authSession, $jsHelper, $data);
62  $this->_moduleList = $moduleList;
63  }
64 
73  public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
74  {
75  $html = $this->_getHeaderHtml($element);
76 
77  $modules = $this->_moduleList->getNames();
78 
79  $dispatchResult = new \Magento\Framework\DataObject($modules);
80  $this->_eventManager->dispatch(
81  'adminhtml_system_config_advanced_disableoutput_render_before',
82  ['modules' => $dispatchResult]
83  );
84  $modules = $dispatchResult->toArray();
85 
86  sort($modules);
87 
88  foreach ($modules as $moduleName) {
89  if ($moduleName === 'Magento_Backend') {
90  continue;
91  }
92  $html .= $this->_getFieldHtml($element, $moduleName);
93  }
94  $html .= $this->_getFooterHtml($element);
95 
96  return $html;
97  }
98 
103  protected function _getDummyElement()
104  {
105  if (empty($this->_dummyElement)) {
106  $this->_dummyElement = new \Magento\Framework\DataObject(['showInDefault' => 1, 'showInWebsite' => 1]);
107  }
108  return $this->_dummyElement;
109  }
110 
115  protected function _getFieldRenderer()
116  {
117  if (empty($this->_fieldRenderer)) {
118  $this->_fieldRenderer = $this->_layout->getBlockSingleton(
119  \Magento\Config\Block\System\Config\Form\Field::class
120  );
121  }
122  return $this->_fieldRenderer;
123  }
124 
129  protected function _getValues()
130  {
131  if (empty($this->_values)) {
132  $this->_values = [
133  ['label' => __('Enable'), 'value' => 0],
134  ['label' => __('Disable'), 'value' => 1],
135  ];
136  }
137  return $this->_values;
138  }
139 
146  protected function _getFieldHtml($fieldset, $moduleName)
147  {
148  $configData = $this->getConfigData();
149  $path = 'advanced/modules_disable_output/' . $moduleName;
150  //TODO: move as property of form
151  if (isset($configData[$path])) {
153  $inherit = false;
154  } else {
155  $data = (int)(string)$this->getForm()->getConfigValue($path);
156  $inherit = true;
157  }
158 
159  $element = $this->_getDummyElement();
160 
161  $field = $fieldset->addField(
162  $moduleName,
163  'select',
164  [
165  'name' => 'groups[modules_disable_output][fields][' . $moduleName . '][value]',
166  'label' => $moduleName,
167  'value' => $data,
168  'values' => $this->_getValues(),
169  'inherit' => $inherit,
170  'can_use_default_value' => $this->getForm()->canUseDefaultValue($element),
171  'can_use_website_value' => $this->getForm()->canUseWebsiteValue($element)
172  ]
173  )->setRenderer(
174  $this->_getFieldRenderer()
175  );
176 
177  return $field->toHtml();
178  }
179 }
__()
Definition: __.php:13
render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
__construct(\Magento\Backend\Block\Context $context, \Magento\Backend\Model\Auth\Session $authSession, \Magento\Framework\View\Helper\Js $jsHelper, \Magento\Framework\Module\ModuleListInterface $moduleList, array $data=[])
$element
Definition: element.phtml:12