0

I want to show user role list in my custom module edit page my code is as below

$fieldset->addField(
       'admin_role_ids',
       'multiselect',
       [
         'name'     => 'permission[admin_role_ids]',
         'label'    => __('Allowed for Roles'),
         'title'    => __('Allowed for Roles'),
         'values'   => $this->_adminSession->getUser()->getRole(),
       ]
    );
2

1) You can use class \Magento\Authorization\Model\ResourceModel\Role\Grid\Collection to get admin roles:

protected $roleCollectionFactory;

public function __construct(
  \Magento\Authorization\Model\ResourceModel\Role\Grid\CollectionFactory $roleCollectionFactory,
) {
  $this->roleCollectionFactory = $roleCollectionFactory;
}

public function getRoles()
{
    $role = $this->roleCollectionFactory->create();
    print_r($role->getData());
}

2) Use class Magento\Authorization\Model\ResourceModel\Role\Collection to get admin role with all admin user:

protected $roleCollectionFactory;

public function __construct(
  \Magento\Authorization\Model\ResourceModel\Role\CollectionFactory $roleCollectionFactory,
) {
  $this->roleCollectionFactory = $roleCollectionFactory;
}

public function getRoles()
{
    $role = $this->roleCollectionFactory->create();
    print_r($role->getData());
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.