Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Formset.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class Formset extends \Magento\Backend\Block\Widget\Form\Generic
11 {
15  protected $_setFactory;
16 
24  public function __construct(
25  \Magento\Backend\Block\Template\Context $context,
26  \Magento\Framework\Registry $registry,
27  \Magento\Framework\Data\FormFactory $formFactory,
28  \Magento\Eav\Model\Entity\Attribute\SetFactory $setFactory,
29  array $data = []
30  ) {
31  $this->_setFactory = $setFactory;
32  parent::__construct($context, $registry, $formFactory, $data);
33  }
34 
40  protected function _prepareForm()
41  {
42  $data = $this->_setFactory->create()->load($this->getRequest()->getParam('id'));
43 
45  $form = $this->_formFactory->create();
46  $fieldset = $form->addFieldset('set_name', ['legend' => __('Edit Attribute Set Name')]);
47  $fieldset->addField(
48  'attribute_set_name',
49  'text',
50  [
51  'label' => __('Name'),
52  'note' => __('For internal use'),
53  'name' => 'attribute_set_name',
54  'required' => true,
55  'class' => 'required-entry validate-no-html-tags',
56  'value' => $data->getAttributeSetName()
57  ]
58  );
59 
60  if (!$this->getRequest()->getParam('id', false)) {
61  $fieldset->addField('gotoEdit', 'hidden', ['name' => 'gotoEdit', 'value' => '1']);
62 
63  $sets = $this->_setFactory->create()->getResourceCollection()->setEntityTypeFilter(
64  $this->_coreRegistry->registry('entityType')
65  )->load()->toOptionArray();
66 
67  $fieldset->addField(
68  'skeleton_set',
69  'select',
70  [
71  'label' => __('Based On'),
72  'name' => 'skeleton_set',
73  'required' => true,
74  'class' => 'required-entry',
75  'values' => $sets
76  ]
77  );
78  }
79 
80  $form->setMethod('post');
81  $form->setUseContainer(true);
82  $form->setId('set-prop-form');
83  $form->setAction($this->getUrl('catalog/*/save'));
84  $form->setOnsubmit('return false;');
85  $this->setForm($form);
86  }
87 }
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Data\FormFactory $formFactory, \Magento\Eav\Model\Entity\Attribute\SetFactory $setFactory, array $data=[])
Definition: Formset.php:24
setForm(\Magento\Framework\Data\Form $form)
Definition: Form.php:112
__()
Definition: __.php:13