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 
8 class Form extends \Magento\Backend\Block\Widget\Form\Generic
9 {
13  protected $_systemStore;
14 
19 
29  public function __construct(
30  \Magento\Backend\Block\Template\Context $context,
31  \Magento\Framework\Registry $registry,
32  \Magento\Framework\Data\FormFactory $formFactory,
33  \Magento\Store\Model\System\Store $systemStore,
34  \Magento\CheckoutAgreements\Model\AgreementModeOptions $agreementModeOptions,
35  array $data = []
36  ) {
37  $this->_systemStore = $systemStore;
38  $this->agreementModeOptions = $agreementModeOptions;
39  parent::__construct($context, $registry, $formFactory, $data);
40  }
41 
47  protected function _construct()
48  {
49  parent::_construct();
50 
51  $this->setId('checkoutAgreementForm');
52  $this->setTitle(__('Terms and Conditions Information'));
53  }
54 
59  protected function _prepareForm()
60  {
61  $model = $this->_coreRegistry->registry('checkout_agreement');
63  $form = $this->_formFactory->create(
64  ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]
65  );
66 
67  $fieldset = $form->addFieldset(
68  'base_fieldset',
69  ['legend' => __('Terms and Conditions Information'), 'class' => 'fieldset-wide']
70  );
71 
72  if ($model->getId()) {
73  $fieldset->addField('agreement_id', 'hidden', ['name' => 'agreement_id']);
74  }
75  $fieldset->addField(
76  'name',
77  'text',
78  [
79  'name' => 'name',
80  'label' => __('Condition Name'),
81  'title' => __('Condition Name'),
82  'required' => true
83  ]
84  );
85 
86  $fieldset->addField(
87  'is_active',
88  'select',
89  [
90  'label' => __('Status'),
91  'title' => __('Status'),
92  'name' => 'is_active',
93  'required' => true,
94  'options' => ['1' => __('Enabled'), '0' => __('Disabled')]
95  ]
96  );
97 
98  $fieldset->addField(
99  'is_html',
100  'select',
101  [
102  'label' => __('Show Content as'),
103  'title' => __('Show Content as'),
104  'name' => 'is_html',
105  'required' => true,
106  'options' => [0 => __('Text'), 1 => __('HTML')]
107  ]
108  );
109 
110  $fieldset->addField(
111  'mode',
112  'select',
113  [
114  'label' => __('Applied'),
115  'title' => __('Applied'),
116  'name' => 'mode',
117  'required' => true,
118  'options' => $this->agreementModeOptions->getOptionsArray()
119  ]
120  );
121 
122  if (!$this->_storeManager->isSingleStoreMode()) {
123  $field = $fieldset->addField(
124  'stores',
125  'multiselect',
126  [
127  'name' => 'stores[]',
128  'label' => __('Store View'),
129  'title' => __('Store View'),
130  'required' => true,
131  'values' => $this->_systemStore->getStoreValuesForForm(false, true)
132  ]
133  );
134  $renderer = $this->getLayout()->createBlock(
135  \Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element::class
136  );
137  $field->setRenderer($renderer);
138  } else {
139  $fieldset->addField(
140  'stores',
141  'hidden',
142  ['name' => 'stores[]', 'value' => $this->_storeManager->getStore(true)->getId()]
143  );
144  $model->setStoreId($this->_storeManager->getStore(true)->getId());
145  }
146 
147  $fieldset->addField(
148  'checkbox_text',
149  'editor',
150  [
151  'name' => 'checkbox_text',
152  'label' => __('Checkbox Text'),
153  'title' => __('Checkbox Text'),
154  'rows' => '5',
155  'cols' => '30',
156  'wysiwyg' => false,
157  'required' => true
158  ]
159  );
160 
161  $fieldset->addField(
162  'content',
163  'editor',
164  [
165  'name' => 'content',
166  'label' => __('Content'),
167  'title' => __('Content'),
168  'style' => 'height:24em;',
169  'wysiwyg' => false,
170  'required' => true
171  ]
172  );
173 
174  $fieldset->addField(
175  'content_height',
176  'text',
177  [
178  'name' => 'content_height',
179  'label' => __('Content Height (css)'),
180  'title' => __('Content Height'),
181  'maxlength' => 25,
182  'class' => 'validate-css-length'
183  ]
184  );
185 
186  $form->setValues($model->getData());
187  $form->setUseContainer(true);
188  $this->setForm($form);
189 
190  return parent::_prepareForm();
191  }
192 }
getData($key='', $index=null)
Definition: DataObject.php:119
setForm(\Magento\Framework\Data\Form $form)
Definition: Form.php:112
__()
Definition: __.php:13
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Data\FormFactory $formFactory, \Magento\Store\Model\System\Store $systemStore, \Magento\CheckoutAgreements\Model\AgreementModeOptions $agreementModeOptions, array $data=[])
Definition: Form.php:29