-
-
Notifications
You must be signed in to change notification settings - Fork 556
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[console] Add UserBase.php Command class. (#3563)
* [console] Add UserBase.php Command class. * [console] Remove PHPStorm docblock.
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Drupal\Console\Command\User; | ||
|
||
use Drupal\Core\Entity\EntityTypeManagerInterface; | ||
use Drupal\Console\Core\Command\Command; | ||
|
||
/** | ||
* Class UserBase | ||
* | ||
* @package Drupal\Console\Command\User | ||
*/ | ||
class UserBase extends Command | ||
{ | ||
/** | ||
* @var EntityTypeManagerInterface | ||
*/ | ||
protected $entityTypeManager; | ||
|
||
/** | ||
* Base constructor. | ||
* | ||
* @param EntityTypeManagerInterface $entityTypeManager | ||
*/ | ||
public function __construct( | ||
EntityTypeManagerInterface $entityTypeManager | ||
) { | ||
$this->entityTypeManager = $entityTypeManager; | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* @param $user mixed | ||
* | ||
* @return mixed | ||
*/ | ||
public function getUserEntity($user) | ||
{ | ||
if (is_numeric($user)) { | ||
$userEntity = $this->entityTypeManager | ||
->getStorage('user') | ||
->load($user); | ||
} else { | ||
$userEntity = reset( | ||
$this->entityTypeManager | ||
->getStorage('user') | ||
->loadByProperties(['name' => $user]) | ||
); | ||
} | ||
|
||
return $userEntity; | ||
} | ||
} |