List all users in product edit page admin panel. Any tutorial or guide please share.
I just created a tab in product edit page but need to show all users details in that tab.
Here's my code:
<?
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Learning\ClothingMaterial\Model\Attribute\Source;
class Material extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
{
/**
* Get all options
* @return array
*/
public function getAllOptions()
{
$roleName = "merchant";
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$roleModel = $objectManager->create('Magento\Authorization\Model\Role');
$userModel = $objectManager->create('Magento\User\Model\User');
$roleModel = $roleModel->load($roleName, 'role_name');
$option_val = [];
if($roleModel->getId()) {
$userIds = $roleModel->getRoleUsers();
foreach($userIds as $userId) {
$user = $userModel->load($userId);
$usernames = $user->getUsername();
$userid = $user->getId();
$option_val['label'] = __($userid - $usernames);
$option_val['value'] = __($userid.$usernames);
}
}
if (!$this->_options) {
$this->_options = [$option_val];
}
return $this->_options;
}
}