Hi Magento friend today's i'm share How to get coustomer group option in ui component form
In Uicomponent create a field -
How we are Integrate the coustomer group options in uicomponent Form -
<field name="coustomer_group" formElement="select">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">Vendor_Name\Module_Name\Model\Options\CustomerGroup</item>
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
<item name="label" translate="true" xsi:type="string">Customer Group</item>
<item name="formElement" xsi:type="string">multiselect</item>
<item name="dataScope" xsi:type="string">coustomer_group</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
Create a file CustomerGroup.php in Vendor_Name\Module_Name\Model\Options\-
<?php
namespace Vendor_Name\Module_Name\Model\Options;
use Magento\Framework\Option\ArrayInterface;
class CustomerGroup implements ArrayInterface {
protected $_customerGroup;
public function __construct(\Magento\Customer\Model\ResourceModel\Group\Collection $customerGroup) {
$this->_customerGroup = $customerGroup;
}
public function toOptionArray() {
$customerGroups = $this->_customerGroup->toOptionArray();
foreach ($customerGroups as $cg) {
if ($cg['label'] !== 'NOT LOGGED IN') {
$this->_options[] = ['label' => $cg['label'], 'value' => $cg['value']];
}
}
return $this->_options;
}
}
<field name="coustomer_group" formElement="select"><argument name="data" xsi:type="array"><item name="options" xsi:type="object">Magento\Customer\Model\Customer\Source\GroupSourceInterface</item><item name="config" xsi:type="array"><item name="dataType" xsi:type="string">text</item><item name="label" translate="true" xsi:type="string">Customer Group</item><item name="formElement" xsi:type="string">multiselect</item><item name="dataScope" xsi:type="string">coustomer_group</item><item name="validation" xsi:type="array"><item name="required-entry" xsi:type="boolean">true</item></item></item></argument></field>