forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPermissionTrait.php
More file actions
86 lines (78 loc) · 2.62 KB
/
Copy pathPermissionTrait.php
File metadata and controls
86 lines (78 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* @file
* Contains Drupal\AppConsole\Command\Helper\PermissionsTrait.
*/
namespace Drupal\AppConsole\Command\Helper;
use Symfony\Component\Console\Helper\HelperInterface;
use Symfony\Component\Console\Output\OutputInterface;
trait PermissionTrait
{
/**
* @param OutputInterface $output
* @param HelperInterface $dialog
*
* @return mixed
*/
public function permissionQuestion(
OutputInterface $output,
HelperInterface $dialog
) {
$permissions = [];
$boolOrNone = ['true','false','none'];
while (true) {
$permission = $dialog->ask(
$output,
$dialog->getQuestion($this->trans('commands.generate.permission.questions.permission'),
'access content'),
'access content'
);
$title = $dialog->ask(
$output,
$dialog->getQuestion($this->trans('commands.generate.permission.questions.title'),
'Access content'),
'Access content'
);
$description = $dialog->ask(
$output,
$dialog->getQuestion($this->trans('commands.generate.permission.questions.description'),
'Allow access to my content'),
'Allow access to my content'
);
$restrictAccess = $dialog->askAndValidate(
$output,
$dialog->getQuestion($this->trans('commands.generate.permission.questions.restrict-access'),
'none', '?'),
function ($answer) use ($boolOrNone) {
if (!in_array($answer, $boolOrNone)) {
throw new \RuntimeException(
'The values can be true, false or none'
);
}
return $answer;
},
false,
'none',
$boolOrNone
);
$permission = $this->getStringUtils()->camelCaseToLowerCase($permission);
$title = $this->getStringUtils()->anyCaseToUcFirst($title);
array_push($permissions, array(
'permission' => $permission,
'title' => $title,
'description' => $description,
'restrict_access' => $restrictAccess,
));
if (!$dialog->askConfirmation(
$output,
$dialog->getQuestion($this->trans('commands.generate.permission.questions.add'),
'yes', '?'),
true
)
) {
break;
}
}
return $permissions;
}
}