Question

I have Custom Edit page in Adminpanel as below: Edit Form

Above Reply textbox, I want to show other records from my custom table in custom HTML format. but not sure how can i use custom html format there!!

My edit page code:

<?php


namespace Vendor\Module\Block\Adminhtml\Items\Edit\Tab;

use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Backend\Block\Widget\Tab\TabInterface;

class Reply extends Generic implements TabInterface
{
    protected $_wysiwygConfig;
    protected $layoutFactory;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context, 
        \Magento\Framework\Registry $registry, 
        \Magento\Framework\Data\FormFactory $formFactory,  
        \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig, 
        \Magento\Framework\View\LayoutFactory $layoutFactory,
        array $data = []
    ) 
    {
        $this->_wysiwygConfig = $wysiwygConfig;
        $this->layoutFactory = $layoutFactory;
        parent::__construct($context, $registry, $formFactory, $data);
    }

    /**
     * {@inheritdoc}
     */
    public function getTabLabel()
    {
        return __('Replies');
    }

    /**
     * {@inheritdoc}
     */
    public function getTabTitle()
    {
        return __('Replies');
    }

    /**
     * {@inheritdoc}
     */
    public function canShowTab()
    {
        return true;
    }

    /**
     * {@inheritdoc}
     */
    public function isHidden()
    {
        return false;
    }

    /**
     * Prepare form before rendering HTML
     *
     * @return $this
     * @SuppressWarnings(PHPMD.NPathComplexity)
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    protected function _prepareForm()
    {


        $model = $this->_coreRegistry->registry('current_custom_items');

        $updates = $this->_coreRegistry->registry('current_custom_updates');

   /**** In $updates i get Collection of records which i want to show above Reply textbox ***/

        /** @var \Magento\Framework\Data\Form $form */
        $form = $this->_formFactory->create();
        $form->setHtmlIdPrefix('item_');
        $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Replies ')]);


        if ($model->getId()) {
            $fieldset->addField('id', 'hidden', ['name' => 'id']);
        }

        $fieldset->addField(
            'Reply',
            'textarea',
            [
                'name' => 'comment',
                'label' => __('Reply'),
                'title' => __('Reply'),
                'required'  => true
            ]
        );

        $form->setValues($model->getData());
        $this->setForm($form);
        return parent::_prepareForm();
    }
}

Was it helpful?

Solution 2

Code which worked for me

 foreach($updates as $update)
       {

            $fieldset->addField('note'.$update['id'], 'note', array(
                'text'     => $update['comment']
            ));
       }

OTHER TIPS

You can try this code to show your already data there.

$fieldset->addField('note', 'note', array(
          'text'     => __($updates),
));

Or you can use this one.

$fieldset->addField('label', 'label', array(
          'value'     => __($updates),
));
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top