Skip to content

Commit

Permalink
[user:*] Updates for user commands (#3667)
Browse files Browse the repository at this point in the history
* user-pass: Added updates for upr command.

* user-command: Updates for user commands.

* user-command: Added updates for user commands.

* [user:*]: Fix code styles.
  • Loading branch information
miguel303 authored and jmolivas committed Jan 10, 2018
1 parent 78b6fd8 commit 1e8be8b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
9 changes: 1 addition & 8 deletions src/Command/User/LoginUrlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);

$user = $input->getArgument('user');
if (!$user) {
$user = $io->ask(
$this->trans('commands.user.login.url.questions.user')
);

$input->setArgument('user', $user);
}
$this->userQuestion();
}

/**
Expand Down
9 changes: 1 addition & 8 deletions src/Command/User/PasswordResetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);

$user = $input->getArgument('user');
if (!$user) {
$user = $io->ask(
$this->trans('commands.user.password.reset.questions.user')
);

$input->setArgument('user', $user);
}
$this->userQuestion();

$password = $input->getArgument('password');
if (!$password) {
Expand Down
34 changes: 34 additions & 0 deletions src/Command/User/UserBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class UserBase extends Command
*/
protected $entityTypeManager;


/**
* Base constructor.
*
Expand Down Expand Up @@ -50,4 +51,37 @@ public function getUserEntity($user)

return $userEntity;
}

/***
* @return array users from site
*/
public function getUsers()
{
$userStorage = $this->entityTypeManager->getStorage('user');
$users = $userStorage->loadMultiple();

$userList = [];
foreach ($users as $userId => $user) {
$userList[$userId] = $user->getUsername();
}

return $userList;
}

public function userQuestion()
{
$input = $this->getIo()->getInput();
$user = $input->getArgument('user');

if (!$user) {
$user = $this->getIo()->choiceNoList(
$this->trans('commands.user.password.reset.questions.user'),
$this->getUsers()
);

$input->setArgument('user', $user);
}

return $user;
}
}

0 comments on commit 1e8be8b

Please sign in to comment.