-
-
Notifications
You must be signed in to change notification settings - Fork 560
/
ModuleTrait.php
57 lines (46 loc) · 1.49 KB
/
ModuleTrait.php
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
<?php
/**
* @file
* Contains Drupal\Console\Command\Shared\ModuleTrait.
*/
namespace Drupal\Console\Command\Shared;
use Drupal\Console\Style\DrupalStyle;
/**
* Class ModuleTrait
* @package Drupal\Console\Command
*/
trait ModuleTrait
{
/**
* @param \Drupal\Console\Style\DrupalStyle $io
* @param bool|true $showProfile
* @return string
* @throws \Exception
*/
public function moduleQuestion(DrupalStyle $io, $showProfile = true)
{
$modules = $this->getApplication()->getSite()->getModules(false, true, true, false, true, true);
if ($showProfile) {
$modules[] = $this->getApplication()->getSite()->getProfile(false, true);
}
if (empty($modules)) {
throw new \Exception('No modules available, execute `generate:module` command to generate one.');
}
$module = $io->choiceNoList(
$this->trans('commands.common.questions.module'),
$modules
);
return $module;
}
public function moduleRequirement($module)
{
foreach ($module as $module_name) {
module_load_install($module_name);
if ($requirements = \Drupal::moduleHandler()->invoke($module_name, 'requirements', array('install'))) {
foreach ($requirements as $requirement) {
throw new \Exception($module_name .' can not be installed: ' . $requirement['description']);
}
}
}
}
}