0

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();
    }
}

3
  • Can you please describe what you want to show here? I mean into this page what you want to show? – Dhiren Vasoya Jul 12 '19 at 13:01
  • it's list of records. may be i can use table format or other div format to display those records – Khushbu Jul 12 '19 at 13:02
  • I am already getting in $updates. It's collection of records – Khushbu Jul 12 '19 at 13:03
1

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),
));
5
  • Ok i try this one – Khushbu Jul 12 '19 at 13:09
  • I tried this but after this code nothing showing in edit page! – Khushbu Jul 12 '19 at 13:16
  • Check system log file, is there any thing show there? – Dhiren Vasoya Jul 12 '19 at 13:22
  • I had to make some changes but it worked – Khushbu Jul 12 '19 at 13:32
  • Great, if answer help you accept as solution so it help other in community as well. – Dhiren Vasoya Jul 12 '19 at 13:34
0

Code which worked for me

 foreach($updates as $update)
       {

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.