-
-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[console] Create roles commands (#3588)
- Loading branch information
Showing
8 changed files
with
490 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
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
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,6 @@ | ||
services: | ||
console.role_new: | ||
class: Drupal\Console\Command\Role\NewCommand | ||
arguments: ['@database', '@entity_type.manager', '@date.formatter', '@console.drupal_api', '@console.validator', '@console.string_converter'] | ||
tags: | ||
- { name: drupal.command } |
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
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,107 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\Console\Command\Create\RolesCommand. | ||
*/ | ||
|
||
namespace Drupal\Console\Command\Create; | ||
|
||
use Drupal\Console\Utils\Create\RoleData; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Drupal\Console\Core\Command\Command; | ||
use Drupal\Console\Core\Style\DrupalStyle; | ||
|
||
/** | ||
* Class RolesCommand | ||
* | ||
* @package Drupal\Console\Command\Create | ||
*/ | ||
class RolesCommand extends Command | ||
{ | ||
/** | ||
* @var RoleData | ||
*/ | ||
protected $createRoleData; | ||
|
||
/** | ||
* RolesCommand constructor. | ||
* | ||
* @param RoleData $createRoleData | ||
*/ | ||
public function __construct( | ||
RoleData $createRoleData | ||
) { | ||
$this->createRoleData = $createRoleData; | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('create:roles') | ||
->setDescription($this->trans('commands.create.roles.description')) | ||
->addOption( | ||
'limit', | ||
null, | ||
InputOption::VALUE_OPTIONAL, | ||
$this->trans('commands.create.roles.options.limit') | ||
) | ||
->setAliases(['crr']); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function interact(InputInterface $input, OutputInterface $output) | ||
{ | ||
$io = new DrupalStyle($input, $output); | ||
|
||
$limit = $input->getOption('limit'); | ||
if (!$limit) { | ||
$limit = $io->ask( | ||
$this->trans('commands.create.roles.questions.limit'), | ||
5 | ||
); | ||
$input->setOption('limit', $limit); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$io = new DrupalStyle($input, $output); | ||
|
||
$limit = $input->getOption('limit')?:5; | ||
|
||
$roles = $this->createRoleData->create( | ||
$limit | ||
); | ||
|
||
$tableHeader = [ | ||
$this->trans('commands.create.roles.messages.role-id'), | ||
$this->trans('commands.create.roles.messages.role-name'), | ||
]; | ||
|
||
if ($roles['success']) { | ||
$io->table($tableHeader, $roles['success']); | ||
|
||
$io->success( | ||
sprintf( | ||
$this->trans('commands.create.roles.messages.created-roles'), | ||
$limit | ||
) | ||
); | ||
} | ||
|
||
return 0; | ||
} | ||
} |
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,75 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\Console\Command\Roles\DebugCommand. | ||
*/ | ||
|
||
namespace Drupal\Console\Command\Debug; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Drupal\Console\Core\Command\Command; | ||
use Drupal\Console\Core\Style\DrupalStyle; | ||
use Drupal\Console\Utils\DrupalApi; | ||
|
||
/** | ||
* Class RolesCommand | ||
* | ||
* @package Drupal\Console\Command\Debug | ||
*/ | ||
class RolesCommand extends Command | ||
{ | ||
/** | ||
* @var DrupalApi | ||
*/ | ||
protected $drupalApi; | ||
|
||
/** | ||
* DebugCommand constructor. | ||
* | ||
* @param DrupalApi $drupalApi | ||
*/ | ||
public function __construct( | ||
DrupalApi $drupalApi | ||
) { | ||
$this->drupalApi = $drupalApi; | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('debug:roles') | ||
->setDescription($this->trans('commands.debug.roles.description')) | ||
->setAliases(['dusr']); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$io = new DrupalStyle($input, $output); | ||
|
||
$roles = $this->drupalApi->getRoles(); | ||
|
||
$tableHeader = [ | ||
$this->trans('commands.debug.roles.messages.role-id'), | ||
$this->trans('commands.debug.roles.messages.role-name'), | ||
]; | ||
|
||
$tableRows = []; | ||
foreach ($roles as $roleId => $role) { | ||
$tableRows[] = [ | ||
$roleId, | ||
$role | ||
]; | ||
} | ||
|
||
$io->table($tableHeader, $tableRows); | ||
} | ||
} |
Oops, something went wrong.