1

Display Multiple Images from database in custom admin edit form This Is My Form.php file

  <?php

namespace Magneto\AppNotification\Block\Adminhtml\Form\Edit\Tab;

  use Magento\Backend\Block\Widget\Form\Generic;
  use Magento\Backend\Block\Widget\Tab\TabInterface;
  use Magento\Backend\Block\Template\Context;
  use Magento\Framework\Registry;
  use Magento\Framework\Data\FormFactory;
  use Magento\Cms\Model\Wysiwyg\Config;


 class Info extends Generic implements TabInterface
 {

 protected $_customerFactory;
 public function __construct(
      \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerFactory,

    Context $context,
    Registry $registry,
    FormFactory $formFactory,
    array $data = []
) {
      $this->_customerFactory = $customerFactory;

    parent::__construct($context, $registry, $formFactory, $data);

}

public function getCustomerCollection()
 {
return $this->_customerFactory->create();
 }

/**
 * Prepare form fields
 *
 * @return \Magento\Backend\Block\Widget\Form
 */
 public function getCustomerdata()
  {
  $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
   $customersdata = $objectManager- 
       >create('Magento\Customer\Model\Customer')
  ->getCollection()->getData();
   return $customersdata;
   }

protected function _prepareForm()
{
     $customerCollection2 = $this->getCustomerdata();


            $jp = array();           
        foreach ($customerCollection2 as $customer) {
            $pp =  $customer['firstname'];
            array_push($jp, $pp);
        }
         // print_r($jp);
         //  die();   

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

    // die($model->getImage());
    // /** @var \Magento\Framework\Data\Form $form */
    $form = $this->_formFactory->create();

    // $form->setHtmlIdPrefix('notification_');
    // $form->setFieldNameSuffix('notification');
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
     $groupOptions = $objectManager->get('\Magneto\AppNotification\Model\Source\Customers')->toOptionArray();

    $fieldset = $form->addFieldset(
        'base_fieldset',
        ['legend' => __('AppNotification')]
    );

    if ($model->getId()) {
        $fieldset->addField(
            'id',
            'hidden',
            ['name' => 'id']
        );
    }
    $fieldset->addField(
        'title',
        'text',
        [
            'name'        => 'title',
            'label'    => __('Title'),
            'required'     => true
        ]
    );
    $fieldset->addField(
        'subtitle',
        'text',
        [
            'name'        => 'subtitle',
            'label'    => __('Sub Title'),
            'required'     => true
        ]
    );
  $fieldset->addField(
'image', 'image', [
'name' => 'image',
'note'=>"Allowed Types('jpg','jpeg','gif','png')",
'label' => __('Upload Image'),
'title' => __('Upload Image'),

    ]

);




 $fieldset->addField(
'customer_id',
'multiselect',
[
    'name' => 'customer_id[]',
    'label' => __('Customer Name'),
    'title' => __('Customer Name'),
    'values'=>$groupOptions
]
);

    $data = $model->getData();
    // print_r($data);die();
    $form->setValues($data);
    $this->setForm($form);


    return parent::_prepareForm();
}

/**
 * Prepare label for tab
 *
 * @return string
 */
public function getTabLabel()
{
    return __('AppNotification Info');
}

/**
 * Prepare title for tab
 *
 * @return string
 */
public function getTabTitle()
{
    return __('AppNotification Info');
}

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

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


 }

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.