i have fetched the all the categories in drop thorugh ui component but i dont know how to give it a look of a parent child drop down can any one help by updating my code?
category_banner_form.xml
<!-- drop down -->
<field name="admin_category_form_field">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">FSDCategoryBannerModelCategory</item>
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
<item name="label" translate="true" xsi:type="string">Category</item>
<item name="formElement" xsi:type="string">select</item>
<item name="source" xsi:type="string">name</item>
<item name="sortOrder" xsi:type="number">20</item>
<item name="dataScope" xsi:type="string">admin_category_form_field</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">false</item>
</item>
</item>
</argument>
</field>
<!-- end drop down -->
category.php
<?php
namespace FSDCategoryBannerModel;
class Category implements MagentoFrameworkOptionArrayInterface
{
protected $_categories;
protected $_storeManager;
public function __construct(
MagentoCatalogModelResourceModelCategoryCollectionFactory $collection,
MagentoStoreModelStoreManagerInterface $storeManager
)
{
$this->_categories = $collection;
$this->_storeManager = $storeManager;
}
public function toOptionArray()
{
$categories = $this->_categories->create();
$collection = $categories->addAttributeToSelect('*')->addFieldToFilter('is_active', 1)->setStore($this->_storeManager->getStore());
dd($collection);
$itemArray = array('value' => '', 'label' => '--Please Select--');
//
$categoryArray = array();
$categoryArray[] = $itemArray;
foreach ($collection as $category)
{
$categoryArray[] = array('value' => $category->getId(), 'label' => $category->getName());
}
return $categoryArray;
}
}