Skip to content

Commit

Permalink
[console] Add UserBase.php Command class. (#3563)
Browse files Browse the repository at this point in the history
* [console] Add UserBase.php Command class.

* [console] Remove PHPStorm docblock.
  • Loading branch information
jmolivas authored Oct 29, 2017
1 parent 37103e0 commit b209e90
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/Command/User/UserBase.php
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;
}
}

0 comments on commit b209e90

Please sign in to comment.