How to get coustomer Email List option in ui component form with multiselect

How to get coustomer Email List option in ui component form

Hi Magento friend today's i'm share How to get coustomer Email List option in ui component form 

In Uicomponent create a field - 

How we are Integrate the coustomer Email List options in uicomponent Form - 


  <field name="customer_email" formElement="select">

      <argument name="data" xsi:type="array">

        <item name="options" xsi:type="object">vendor_name\module_name\Model\Options\CustomerEmail</item>

        <item name="config" xsi:type="array">

          <item name="dataType" xsi:type="string">text</item>

          <item name="label" translate="true" xsi:type="string">Select Email</item>

          <item name="formElement" xsi:type="string">multiselect</item>

         <item name="validation" xsi:type="array">

            <item name="required-entry" xsi:type="boolean">true</item>

         </item>

        </item>

      </argument>

    </field>



Create a file CustomerEmail.php in  vendor_name\module_name\Model\Options\


<?php
namespace vendor_name\module_name\Model\Options;
use Magento\Framework\Option\ArrayInterface;
class CustomerEmail implements ArrayInterface {
    protected $_customers;
    public function __construct(\Magento\Customer\Model\Customer $customers) {
        $this->_customers = $customers;
    }
    public function toOptionArray() {
        $customersdata = $this->_customers->getCollection()->addAttributeToSelect("*")->load();
        foreach ($customersdata as $data) {
            $customername = $data->getData('firstname') . " " . $data->getData('lastname');
            $customeremail = $data->getData('email');
            $this->_options[] = ['label' => $customeremail, 'value' => $customeremail];
        }
        return $this->_options;
    }
}

How to get coustomer Email List option in ui component form with multiselect





Deepak Kumar Bind

Success is peace of mind, which is a direct result of self-satisfaction in knowing you made the effort to become the best of which you are capable.

1 Comments

If you liked this post please do not forget to leave a comment. Thanks

Previous Post Next Post