Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Form Class Reference
Inheritance diagram for Form:
Generic Form Widget Template Template AbstractBlock DataObject BlockInterface

Public Member Functions

 __construct (\Magento\Backend\Block\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Data\FormFactory $formFactory, \Magento\Review\Model\Rating\OptionFactory $optionFactory, \Magento\Framework\Session\SessionManagerInterface $session, \Magento\Store\Model\System\Store $systemStore, array $data=[])
 
- Public Member Functions inherited from Generic
 __construct (\Magento\Backend\Block\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Data\FormFactory $formFactory, array $data=[])
 
- Public Member Functions inherited from Form
 __construct (\Magento\Backend\Block\Template\Context $context, array $data=[])
 
 getForm ()
 
 getFormHtml ()
 
 setForm (\Magento\Framework\Data\Form $form)
 
- Public Member Functions inherited from Widget
 getId ()
 
 getSuffixId ($suffix)
 
 getHtmlId ()
 
 getCurrentUrl ($params=[])
 
 getButtonHtml ($label, $onclick, $class='', $buttonId=null, $dataAttr=[])
 
- Public Member Functions inherited from Template
 __construct (\Magento\Backend\Block\Template\Context $context, array $data=[])
 
 getFormKey ()
 
 isOutputEnabled ($moduleName=null)
 
 getAuthorization ()
 
 getToolbar ()
 
- Public Member Functions inherited from Template
 __construct (Template\Context $context, array $data=[])
 
 setTemplateContext ($templateContext)
 
 getTemplate ()
 
 setTemplate ($template)
 
 getTemplateFile ($template=null)
 
 getArea ()
 
 assign ($key, $value=null)
 
 fetchView ($fileName)
 
 getBaseUrl ()
 
 getObjectData (\Magento\Framework\DataObject $object, $key)
 
 getCacheKeyInfo ()
 
- Public Member Functions inherited from AbstractBlock
 __construct (\Magento\Framework\View\Element\Context $context, array $data=[])
 
 getJsLayout ()
 
 getRequest ()
 
 getParentBlock ()
 
 setLayout (\Magento\Framework\View\LayoutInterface $layout)
 
 getLayout ()
 
 setNameInLayout ($name)
 
 getChildNames ()
 
 setAttribute ($name, $value=null)
 
 setChild ($alias, $block)
 
 addChild ($alias, $block, $data=[])
 
 unsetChild ($alias)
 
 unsetCallChild ($alias, $callback, $result, $params)
 
 unsetChildren ()
 
 getChildBlock ($alias)
 
 getChildHtml ($alias='', $useCache=true)
 
 getChildChildHtml ($alias, $childChildAlias='', $useCache=true)
 
 getBlockHtml ($name)
 
 insert ($element, $siblingName=0, $after=true, $alias='')
 
 append ($element, $alias='')
 
 getGroupChildNames ($groupName)
 
 getChildData ($alias, $key='')
 
 getUiId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getJsId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getUrl ($route='', $params=[])
 
 getViewFileUrl ($fileId, array $params=[])
 
 formatDate ( $date=null, $format=\IntlDateFormatter::SHORT, $showTime=false, $timezone=null)
 
 formatTime ( $time=null, $format=\IntlDateFormatter::SHORT, $showDate=false)
 
 getModuleName ()
 
 escapeHtml ($data, $allowedTags=null)
 
 escapeJs ($string)
 
 escapeHtmlAttr ($string, $escapeSingleQuote=true)
 
 escapeCss ($string)
 
 stripTags ($data, $allowableTags=null, $allowHtmlEntities=false)
 
 escapeUrl ($string)
 
 escapeXssInUrl ($data)
 
 escapeQuote ($data, $addSlashes=false)
 
 escapeJsQuote ($data, $quote='\'')
 
 getNameInLayout ()
 
 getCacheKeyInfo ()
 
 getCacheKey ()
 
 getVar ($name, $module=null)
 
 isScopePrivate ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from BlockInterface
 toHtml ()
 

Protected Member Functions

 _prepareForm ()
 
 addRatingFieldset ()
 
 setRatingData ()
 
 setRatingCodes ($ratingCodes)
 
 setRatingOptions ()
 
 addVisibilityFieldset ()
 
 initFieldset ($formId, array $config)
 
 getFieldset ($formId)
 
- Protected Member Functions inherited from Form
 _construct ()
 
 _prepareLayout ()
 
 _prepareForm ()
 
 _beforeToHtml ()
 
 _initFormValues ()
 
 _setFieldset ($attributes, $fieldset, $exclude=[])
 
 _isAttributeVisible (\Magento\Eav\Model\Entity\Attribute $attribute)
 
 _applyTypeSpecificConfig ($inputType, $element, \Magento\Eav\Model\Entity\Attribute $attribute)
 
 _addElementTypes (\Magento\Framework\Data\Form\AbstractForm $baseElement)
 
 _getAdditionalElementTypes ()
 
 _getAdditionalElementHtml ($element)
 
- Protected Member Functions inherited from Widget
 _addBreadcrumb ($label, $title=null, $link=null)
 
- Protected Member Functions inherited from Template
 _toHtml ()
 
- Protected Member Functions inherited from Template
 _construct ()
 
 _toHtml ()
 
 getRootDirectory ()
 
 getMediaDirectory ()
 
- Protected Member Functions inherited from AbstractBlock
 _construct ()
 
 _prepareLayout ()
 
 _beforeToHtml ()
 
 _afterToHtml ($html)
 
 _toHtml ()
 
 _getNotFoundUrl ($route='', $params=['_direct'=> 'core/index/notFound'])
 
 getCacheTags ()
 
 getCacheLifetime ()
 
 _loadCache ()
 
 _saveCache ($data)
 
 _getSidPlaceholder ($cacheKey=null)
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $systemStore
 
 $_template = 'Magento_Review::rating/form.phtml'
 
 $session
 
 $optionFactory
 
 $fieldset
 
- Protected Attributes inherited from Generic
 $_formFactory
 
 $_coreRegistry
 
- Protected Attributes inherited from Form
 $_form
 
 $_template = 'Magento_Backend::widget/form.phtml'
 
- Protected Attributes inherited from Template
 $_authorization
 
 $mathRandom
 
 $_backendSession
 
 $formKey
 
 $nameBuilder
 
- Protected Attributes inherited from Template
 $_viewVars = []
 
 $_baseUrl
 
 $_jsUrl
 
 $_allowSymlinks
 
 $_filesystem
 
 $_template
 
 $templateEnginePool
 
 $_storeManager
 
 $_appState
 
 $directory
 
 $templateContext
 
 $pageConfig
 
 $resolver
 
 $validator
 
- Protected Attributes inherited from AbstractBlock
 $_design
 
 $_session
 
 $_sidResolver
 
 $_nameInLayout
 
 $_layout
 
 $jsLayout = []
 
 $_request
 
 $_urlBuilder
 
 $_eventManager
 
 $_frontController
 
 $_assetRepo
 
 $_viewConfig
 
 $_cacheState
 
 $_logger
 
 $_escaper
 
 $filterManager
 
 $_localeDate
 
 $inlineTranslation
 
 $_isScopePrivate = false
 
 $_scopeConfig
 
 $_cache
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Public Member Functions inherited from AbstractBlock
static extractModuleName ($className)
 
- Data Fields inherited from Template
const XML_PATH_TEMPLATE_ALLOW_SYMLINK = 'dev/template/allow_symlink'
 
- Data Fields inherited from AbstractBlock
const CACHE_GROUP = \Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER
 
const CACHE_KEY_PREFIX = 'BLOCK_'
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Definition at line 8 of file Form.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Backend\Block\Template\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Framework\Data\FormFactory  $formFactory,
\Magento\Review\Model\Rating\OptionFactory  $optionFactory,
\Magento\Framework\Session\SessionManagerInterface  $session,
\Magento\Store\Model\System\Store  $systemStore,
array  $data = [] 
)
Parameters
\Magento\Backend\Block\Template\Context$context
\Magento\Framework\Registry$registry
\Magento\Framework\Data\FormFactory$formFactory
\Magento\Review\Model\Rating\OptionFactory$optionFactory
\Magento\Framework\Session\SessionManagerInterface$session
\Magento\Store\Model\System\Store$systemStore
array$data

Definition at line 50 of file Form.php.

58  {
59  $this->optionFactory = $optionFactory;
60  $this->session = $session;
61  $this->systemStore = $systemStore;
62  parent::__construct($context, $registry, $formFactory, $data);
63  }

Member Function Documentation

◆ _prepareForm()

_prepareForm ( )
protected

Prepare rating edit form

Returns
$this @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity) @SuppressWarnings(PHPMD.ExcessiveMethodLength)

Definition at line 73 of file Form.php.

74  {
75  $this->setForm($this->_formFactory->create());
76  $this->addRatingFieldset();
77  $this->addVisibilityFieldset();
78  if ($this->_coreRegistry->registry('rating_data')) {
79  $this->getForm()->getElement('position')->setValue(
80  $this->_coreRegistry->registry('rating_data')->getPosition()
81  );
82  $this->getForm()->getElement('is_active')->setIsChecked(
83  $this->_coreRegistry->registry('rating_data')->getIsActive()
84  );
85  }
86 
87  return parent::_prepareForm();
88  }
setForm(\Magento\Framework\Data\Form $form)
Definition: Form.php:112

◆ addRatingFieldset()

addRatingFieldset ( )
protected

Add rating fieldset to form

Returns
void

Definition at line 95 of file Form.php.

96  {
97  $this->initFieldset('rating_form', ['legend' => __('Rating Title')]);
98  $this->getFieldset('rating_form')->addField(
99  'rating_code',
100  'text',
101  [
102  'name' => 'rating_code',
103  'label' => __('Default Value'),
104  'class' => 'required-entry',
105  'required' => true
106  ]
107  );
108 
109  foreach ($this->systemStore->getStoreCollection() as $store) {
110  $this->getFieldset('rating_form')->addField(
111  'rating_code_' . $store->getId(),
112  'text',
113  ['label' => $store->getName(), 'name' => 'rating_codes[' . $store->getId() . ']']
114  );
115  }
116  $this->setRatingData();
117  }
__()
Definition: __.php:13

◆ addVisibilityFieldset()

addVisibilityFieldset ( )
protected

Add visibility fieldset to form

Returns
void

Definition at line 201 of file Form.php.

202  {
203  $this->initFieldset('visibility_form', ['legend' => __('Rating Visibility')]);
204  if (!$this->_storeManager->isSingleStoreMode()) {
205  $field = $this->getFieldset('visibility_form')->addField(
206  'stores',
207  'multiselect',
208  [
209  'label' => __('Visibility'),
210  'name' => 'stores[]',
211  'values' => $this->systemStore->getStoreValuesForForm()
212  ]
213  );
214  $renderer = $this->getLayout()->createBlock(
215  \Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element::class
216  );
217  $field->setRenderer($renderer);
218  if ($this->_coreRegistry->registry('rating_data')) {
219  $this->getForm()->getElement('stores')->setValue(
220  $this->_coreRegistry->registry('rating_data')->getStores()
221  );
222  }
223  }
224  $this->getFieldset('visibility_form')->addField(
225  'is_active',
226  'checkbox',
227  ['label' => __('Is Active'), 'name' => 'is_active', 'value' => 1]
228  );
229  $this->getFieldset('visibility_form')
230  ->addField('position', 'text', ['label' => __('Sort Order'), 'name' => 'position']);
231  }
__()
Definition: __.php:13

◆ getFieldset()

getFieldset (   $formId)
protected

Get fieldset by form id

Parameters
string$formId
Returns
\Magento\Framework\Data\Form\Element\Fieldset|null

Definition at line 257 of file Form.php.

258  {
259  if (!empty($this->fieldset) && isset($this->fieldset[$formId])) {
260  return $this->fieldset[$formId];
261  } else {
262  return null;
263  }
264  }

◆ initFieldset()

initFieldset (   $formId,
array  $config 
)
protected

Initialize form fieldset

Parameters
string$formId
array$config
Returns
void

Definition at line 240 of file Form.php.

241  {
242  if (!isset($this->fieldset[$formId])) {
243  if (!$this->getForm()->getElement($formId)) {
244  $this->fieldset[$formId] = $this->getForm()->addFieldset($formId, $config);
245  } elseif ($this->getForm()->getElement($formId)) {
246  //do nothing
247  }
248  }
249  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$config
Definition: fraud_order.php:17

◆ setRatingCodes()

setRatingCodes (   $ratingCodes)
protected

Set rating codes to form

Parameters
array$ratingCodes
Returns
void

Definition at line 149 of file Form.php.

150  {
151  foreach ($ratingCodes as $store => $value) {
152  $element = $this->getForm()->getElement('rating_code_' . $store);
153  if ($element) {
154  $element->setValue($value);
155  }
156  }
157  }
$value
Definition: gender.phtml:16
$element
Definition: element.phtml:12

◆ setRatingData()

setRatingData ( )
protected

Set rating data to form

Returns
void

Definition at line 124 of file Form.php.

125  {
126  if ($this->session->getRatingData()) {
127  $this->getForm()->setValues($this->session->getRatingData());
128  $data = $this->session->getRatingData();
129  if (isset($data['rating_codes'])) {
130  $this->setRatingCodes($data['rating_codes']);
131  }
132  $this->session->setRatingData(null);
133  } elseif ($this->_coreRegistry->registry('rating_data')) {
134  $this->getForm()->setValues($this->_coreRegistry->registry('rating_data')->getData());
135  if ($this->_coreRegistry->registry('rating_data')->getRatingCodes()) {
136  $this->setRatingCodes($this->_coreRegistry->registry('rating_data')->getRatingCodes());
137  }
138  }
139 
140  $this->setRatingOptions();
141  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ setRatingOptions()

setRatingOptions ( )
protected

Set rating options to form

Returns
void

Definition at line 164 of file Form.php.

165  {
166  if ($this->_coreRegistry->registry('rating_data')) {
167  $collection = $this->optionFactory->create()->getResourceCollection()->addRatingFilter(
168  $this->_coreRegistry->registry('rating_data')->getId()
169  )->load();
170 
171  $i = 1;
172  foreach ($collection->getItems() as $item) {
173  $this->getFieldset('rating_form')->addField(
174  'option_code_' . $item->getId(),
175  'hidden',
176  [
177  'required' => true,
178  'name' => 'option_title[' . $item->getId() . ']',
179  'value' => $item->getCode() ? $item->getCode() : $i
180  ]
181  );
182 
183  $i++;
184  }
185  } else {
186  for ($i = 1; $i <= 5; $i++) {
187  $this->getFieldset('rating_form')->addField(
188  'option_code_' . $i,
189  'hidden',
190  ['required' => true, 'name' => 'option_title[add_' . $i . ']', 'value' => $i]
191  );
192  }
193  }
194  }
$i
Definition: gallery.phtml:31

Field Documentation

◆ $_template

$_template = 'Magento_Review::rating/form.phtml'
protected

Definition at line 20 of file Form.php.

◆ $fieldset

$fieldset
protected

Definition at line 39 of file Form.php.

◆ $optionFactory

$optionFactory
protected

Definition at line 34 of file Form.php.

◆ $session

$session
protected

Definition at line 27 of file Form.php.

◆ $systemStore

$systemStore
protected

Definition at line 15 of file Form.php.


The documentation for this class was generated from the following file: