I'm working on Custom module in which I need to override Magento's reviews Module. I want to add some extra fields in Magento's Review Form. I created Preferences in adminhtml/di.xml Now whenever I add my custom fields code, all the other fields get removed.
class Form extends \Magento\Backend\Block\Widget\Form\Generic
{
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
\Magento\Store\Model\System\Store $systemStore,
\Magento\Review\Helper\Data $reviewData,
array $data = []
) {
$this->_reviewData = $reviewData;
$this->_systemStore = $systemStore;
parent::__construct($context, $registry, $formFactory, $data);
}
/**
* Prepare add review form
*
* @return void
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function _prepareForm()
{
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create();
$fieldset = $form->addFieldset('add_review_form', ['legend' => __('Review Details')]);
$fieldset->addField('product_name', 'note', ['label' => __('Product'), 'text' => 'product_name']);
// $fieldset->addField(
// 'detailed-rating',
// 'note',
// [
// 'label' => __('Product Rating'),
// 'required' => true,
// 'text' => '<div id="rating_detail">' . $this->getLayout()->createBlock(
// \Magento\Review\Block\Adminhtml\Rating\Detailed::class
// )->toHtml() . '</div>'
// ]
// );
// $fieldset->addField(
// 'status_id',
// 'select',
// [
// 'label' => __('Status'),
// 'required' => true,
// 'name' => 'status_id',
// 'values' => $this->_reviewData->getReviewStatusesOptionArray()
// ]
// );
// /**
// * Check is single store mode
// */
// if (!$this->_storeManager->isSingleStoreMode()) {
// $field = $fieldset->addField(
// 'select_stores',
// 'multiselect',
// [
// 'label' => __('Visibility'),
// 'required' => true,
// 'name' => 'select_stores[]',
// 'values' => $this->_systemStore->getStoreValuesForForm()
// ]
// );
// $renderer = $this->getLayout()->createBlock(
// \Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element::class
// );
// $field->setRenderer($renderer);
// }
// $fieldset->addField(
// 'nickname',
// 'text',
// [
// 'name' => 'nickname',
// 'title' => __('Nickname'),
// 'label' => __('Nickname'),
// 'maxlength' => '50',
// 'required' => true
// ]
// );
// $fieldset->addField(
// 'title',
// 'text',
// [
// 'name' => 'title',
// 'title' => __('Summary of Review'),
// 'label' => __('Summary of Review'),
// 'maxlength' => '255',
// 'required' => true
// ]
// );
// $fieldset->addField(
// 'detail',
// 'textarea',
// [
// 'name' => 'detail',
// 'title' => __('Review'),
// 'label' => __('Review'),
// 'required' => true
// ]
// );
$fieldset->addFieldset(
'review_comment',
['legend' => __('Review Comment'), 'class' => 'fieldset-wide']
);
$fieldset->addField(
'title_comment',
'text',
['label' => __('Title'), 'required' => false, 'name' => 'comment-title']
);
$fieldset->addField(
'comment',
'textarea',
['label' => __('Comment'), 'required' => false, 'name' => 'comment']
);
$fieldset->addField(
'send_customer',
'checkbox',
['label' => __('Send this Comment to customer'), 'required' => false, 'name' => 'show_to_customer']
);
$fieldset->addField('product_id', 'hidden', ['name' => 'product_id']);
/*$gridFieldset = $form->addFieldset('add_review_grid', array('legend' => __('Please select a product')));
$gridFieldset->addField('products_grid', 'note', array(
'text' => $this->getLayout()->createBlock(\Magento\Review\Block\Adminhtml\Product\Grid::class)->toHtml(),
));*/
$form->setMethod('post');
$form->setUseContainer(true);
$form->setId('edit_form');
$form->setAction($this->getUrl('review/product/post'));
$this->setForm($form);
return parent::_prepareForm();
}
}
also, whenever I add my fields using this method $fieldset->addField it gives an error.