This blog post is used for
You can get a first name, last name, and email of current admin user roles by calling User module’s Collection class.
You can fetch current user data by below code snippet,
<?php namespace Path\To\Block; use Magento\Backend\Block\Template\Context; use Magento\Authorization\Model\UserContextInterface; use Magento\User\Model\ResourceModel\User\CollectionFactory as UserCollectionFactory; /** * CurrentAdminUser block */ class CurrentAdminUser extends \Magento\Backend\Block\Template { /** * @var UserContextInterface */ protected $userContext; /** * @var UserCollectionFactory */ private $userCollectionFactory; public function __construct( Context $context, UserContextInterface $userContext, UserCollectionFactory $userCollectionFactory, array $data = [] ) { $this->userContext = $userContext; $this->userCollectionFactory = $userCollectionFactory; parent::__construct($context, $data); } /* Admin User info */ public function getUserData() { $collection = $this->userCollectionFactory->create(); $userId = $this->userContext->getUserId(); $collection->addFieldToFilter('main_table.user_id', $userId); $userData = $collection->getFirstItem(); return $userData->getData(); }
Call function, $this->getUserData() to get Output and based on your requirement you can fetch required data.
Result:
Array ( [user_id] => 7 [firstname] => Rakesh [lastname] => Jesadiya [email] => admin@admintest.com [username] => admin [password] => 4163549099b7476254e4d4cffba9bb40aa7b92c80906838b630452c7e79e7f7 [created] => 2019-07-10 11:50:21 [modified] => 2019-07-18 11:19:06 [logdate] => 2019-07-18 11:19:06 [lognum] => 1 [reload_acl_flag] => 0 [is_active] => 1 [extra] => [rp_token] => [rp_token_created_at] => [interface_locale] => en_US [failures_num] => 0 [first_failure] => [lock_expires] => [refresh_token] => [role_name] => Administrators )