Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Formgroup.php
Go to the documentation of this file.
1 <?php
11 
13 
14 class Formgroup extends \Magento\Backend\Block\Widget\Form\Generic
15 {
19  protected $_typeFactory;
20 
28  public function __construct(
29  \Magento\Backend\Block\Template\Context $context,
30  \Magento\Framework\Registry $registry,
31  \Magento\Framework\Data\FormFactory $formFactory,
32  \Magento\Eav\Model\Entity\TypeFactory $typeFactory,
33  array $data = []
34  ) {
35  $this->_typeFactory = $typeFactory;
36  parent::__construct($context, $registry, $formFactory, $data);
37  }
38 
42  protected function _prepareForm()
43  {
45  $form = $this->_formFactory->create();
46 
47  $fieldset = $form->addFieldset('set_fieldset', ['legend' => __('Add New Group')]);
48 
49  $fieldset->addField(
50  'attribute_group_name',
51  'text',
52  ['label' => __('Name'), 'name' => 'attribute_group_name', 'required' => true]
53  );
54 
55  $fieldset->addField(
56  'submit',
57  'note',
58  [
59  'text' => $this->getLayout()->createBlock(
60  \Magento\Backend\Block\Widget\Button::class
61  )->setData(
62  ['label' => __('Add Group'), 'onclick' => 'this.form.submit();', 'class' => 'add']
63  )->toHtml()
64  ]
65  );
66 
67  $fieldset->addField(
68  'attribute_set_id',
69  'hidden',
70  ['name' => 'attribute_set_id', 'value' => $this->_getSetId()]
71  );
72 
73  $form->setUseContainer(true);
74  $form->setMethod('post');
75  $form->setAction($this->getUrl('catalog/product_group/save'));
76  $this->setForm($form);
77  }
78 
82  protected function _getSetId()
83  {
84  return intval(
85  $this->getRequest()->getParam('id')
86  ) > 0 ? intval(
87  $this->getRequest()->getParam('id')
88  ) : $this->_typeFactory->create()->load(
89  $this->_coreRegistry->registry('entityType')
90  )->getDefaultAttributeSetId();
91  }
92 }
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\Eav\Model\Entity\TypeFactory $typeFactory, array $data=[])
Definition: Formgroup.php:28
setData($key, $value=null)
Definition: DataObject.php:72