Add events to add fields in tab form
For now we have a lot places, that contains code like this:
/** @var \Magento\Data\Form $form */
$form = $this->_formFactory->create();
$fieldset = $form->addFieldset('tiered_price', array('legend' => __('Tier Pricing')));
$fieldset->addField('default_price', 'label', array(
'label' => __('Default Price'),
'title' => __('Default Price'),
'name' => 'default_price',
'bold' => true,
'value' => $product->getPrice()
));
But we haven't events to add additional fields.
Example: https://github.com/magento/magento2/blob/cc63630ec5c248b655b33937e27008c820910cb5/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Price.php#L39
https://github.com/magento/magento2/blob/0849373d7636cfa17b70b8188bfc36d13ae749c1/app/code/Magento/Adminhtml/Block/System/Cache/Form.php#L49
You can use interceptors on setForm to implement this.
@igor-svizev , Did you try the approach suggested by @kandy ? If yes, did this resolve the issue that you had?
@kandy , could you provide example how to make it?
@igor-svizev , we will file this issue to our internal bug tracker. Thank you for reporting this to us!
What going to be use-case with events? It seems like much easier to create new block and configure layout to use it.
@maksek how I can add new fields to existing forms, as example if my module will add some field to admin user form?
You can define "before" plugin on $this->setForm($form) method of block and get $form as arguments, and change form as you need.
@kandy this approach will work, but I think here we need an explicit extension point, same as for addTab
Should this still be open if the tendency is to move to UI components for admin forms?
@tzyganu Very good question. Since we have a couple alternative options to add fields to old forms without explicit event, and taking into account that we are moving to UI Components for admin forms, it is reasonable to close this issue.
I think this issue can be closed