magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Add events to add fields in tab form

Open ihor-sviziev opened this issue 13 years ago • 11 comments

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

ihor-sviziev avatar Nov 07 '13 10:11 ihor-sviziev

You can use interceptors on setForm to implement this.

kandy avatar Nov 07 '13 11:11 kandy

@igor-svizev , Did you try the approach suggested by @kandy ? If yes, did this resolve the issue that you had?

verklov avatar Dec 27 '13 14:12 verklov

@kandy , could you provide example how to make it?

ihor-sviziev avatar Dec 28 '13 08:12 ihor-sviziev

@igor-svizev , we will file this issue to our internal bug tracker. Thank you for reporting this to us!

verklov avatar Jan 03 '14 15:01 verklov

What going to be use-case with events? It seems like much easier to create new block and configure layout to use it.

maksek avatar Jan 08 '15 21:01 maksek

@maksek how I can add new fields to existing forms, as example if my module will add some field to admin user form?

ihor-sviziev avatar Jan 09 '15 10:01 ihor-sviziev

You can define "before" plugin on $this->setForm($form) method of block and get $form as arguments, and change form as you need.

kandy avatar Jan 09 '15 11:01 kandy

@kandy this approach will work, but I think here we need an explicit extension point, same as for addTab

antonkril avatar Jan 09 '15 11:01 antonkril

Should this still be open if the tendency is to move to UI components for admin forms?

tzyganu avatar Jul 11 '16 14:07 tzyganu

@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.

vkorotun avatar Aug 04 '16 06:08 vkorotun

I think this issue can be closed

ihor-sviziev avatar Aug 04 '16 07:08 ihor-sviziev