982c411679434038b5cbc6de41be15e1f9c5f4b0
[yaffs-website] / vendor / drupal / console / src / Command / Shared / ExtensionTrait.php
1 <?php
2
3 /**
4  * @file
5  * Contains Drupal\Console\Command\Shared\ExtensionTrait.
6  */
7
8 namespace Drupal\Console\Command\Shared;
9
10 use Drupal\Console\Core\Style\DrupalStyle;
11
12 /**
13  * Class ExtensionTrait
14  *
15  * @package Drupal\Console\Command
16  */
17 trait ExtensionTrait
18 {
19
20     /**
21      * @param DrupalStyle $io
22      * @param bool|true   $module
23      * @param bool|true   $theme
24      * @param bool|true   $profile
25      *
26      * @return string
27      *
28      * @throws \Exception
29      */
30     public function extensionQuestion(DrupalStyle $io, $module=true, $theme=false, $profile=false)
31     {
32         $modules = [];
33         $themes = [];
34         $profiles = [];
35         if ($module) {
36             $modules = $this->extensionManager->discoverModules()
37                 ->showInstalled()
38                 ->showUninstalled()
39                 ->showNoCore()
40                 ->getList();
41         }
42
43         if ($theme) {
44             $themes = $this->extensionManager->discoverThemes()
45                 ->showInstalled()
46                 ->showUninstalled()
47                 ->showNoCore()
48                 ->getList();
49         }
50
51         if ($profile) {
52             $profiles = $this->extensionManager->discoverProfiles()
53                 ->showInstalled()
54                 ->showUninstalled()
55                 ->showNoCore()
56                 ->showCore()
57                 ->getList();
58         }
59
60         $extensions = array_merge(
61             $modules,
62             $themes,
63             $profiles
64         );
65
66         if (empty($extensions)) {
67             throw new \Exception('No extension available, execute the proper generator command to generate one.');
68         }
69
70         $extension = $io->choiceNoList(
71             $this->trans('commands.common.questions.extension'),
72             array_keys($extensions)
73         );
74
75         return $extensions[$extension];
76     }
77
78     /**
79      * @param DrupalStyle $io
80      *
81      * @return string
82      *
83      * @throws \Exception
84      */
85     public function extensionTypeQuestion(DrupalStyle $io)
86     {
87         $extensionType = $io->choiceNoList(
88             $this->trans('commands.common.questions.extension-type'),
89             array_keys(['module', 'theme', 'profile'])
90         );
91
92         return $extensionType;
93     }
94 }