Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Form.php
Go to the documentation of this file.
1 <?php
7 
13 class Form extends \Magento\Backend\Block\Widget\Form\Generic
14 {
18  protected $cacheTypeList;
19 
27  public function __construct(
28  \Magento\Backend\Block\Template\Context $context,
29  \Magento\Framework\Registry $registry,
30  \Magento\Framework\Data\FormFactory $formFactory,
31  \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
32  array $data = []
33  ) {
34  $this->cacheTypeList = $cacheTypeList;
35  parent::__construct($context, $registry, $formFactory, $data);
36  }
37 
43  public function initForm()
44  {
46  $form = $this->_formFactory->create();
47 
48  $fieldset = $form->addFieldset('cache_enable', ['legend' => __('Cache Control')]);
49 
50  $fieldset->addField(
51  'all_cache',
52  'select',
53  [
54  'name' => 'all_cache',
55  'label' => '<strong>' . __('All Cache') . '</strong>',
56  'value' => 1,
57  'options' => [
58  '' => __('No change'),
59  'refresh' => __('Refresh'),
60  'disable' => __('Disable'),
61  'enable' => __('Enable'),
62  ]
63  ]
64  );
65 
66  foreach ($this->cacheTypeList->getTypeLabels() as $type => $label) {
67  $fieldset->addField(
68  'enable_' . $type,
69  'checkbox',
70  [
71  'name' => 'enable[' . $type . ']',
72  'label' => __($label),
73  'value' => 1,
74  'checked' => (int)$this->_cacheState->isEnabled($type)
75  ]
76  );
77  }
78  $this->setForm($form);
79  return $this;
80  }
81 }
setForm(\Magento\Framework\Data\Form $form)
Definition: Form.php:112
__()
Definition: __.php:13
$type
Definition: item.phtml:13
$label
Definition: details.phtml:21
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Data\FormFactory $formFactory, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, array $data=[])
Definition: Form.php:27