Skip to content

Commit 44c8d8c

Browse files
gilbertomangonesenzolutions
authored andcommitted
Add option install theme with release version (#4158)
* Add option install theme with realease version * Add validation theme:install not found theme
1 parent e9e4d3a commit 44c8d8c

File tree

5 files changed

+123
-7
lines changed

5 files changed

+123
-7
lines changed

config/services/theme.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services:
66
- { name: drupal.command }
77
console.theme_install:
88
class: Drupal\Console\Command\Theme\InstallCommand
9-
arguments: ['@config.factory', '@theme_handler', '@console.chain_queue']
9+
arguments: ['@config.factory', '@theme_handler', '@console.chain_queue', '@console.site', '@console.validator','@module_installer','@console.drupal_api','@console.extension_manager','@app.root']
1010
tags:
1111
- { name: drupal.command }
1212
console.theme_path:

src/Command/Shared/ProjectDownloadTrait.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,49 @@ private function downloadModules($modules, $latest, $path = null, $resultList =
128128

129129
return $this->downloadModules($dependencies, $latest, $path, $resultList);
130130
}
131+
132+
private function downloadThemes($themes, $latest, $path = null, $resultList = [])
133+
{
134+
if (!$resultList) {
135+
$resultList = [
136+
'invalid' => [],
137+
'uninstalled' => [],
138+
'dependencies' => []
139+
];
140+
}
141+
drupal_static_reset('system_rebuild_module_data');
142+
143+
$missingThemes = $this->validator->getMissingThemes($themes);
144+
145+
$invalidModules = [];
146+
if ($missingThemes) {
147+
$this->getIo()->info(
148+
sprintf(
149+
$this->trans('commands.theme.install.messages.theme-missing'),
150+
implode(', ', $missingThemes)
151+
)
152+
);
153+
foreach ($missingThemes as $missingTheme) {
154+
$version = $this->releasesQuestion($missingTheme, $latest);
155+
if ($version) {
156+
$this->downloadProject($missingTheme, $version, 'theme', $path);
157+
} else {
158+
$invalidModules[] = $missingTheme;
159+
unset($themes[array_search($missingTheme, $themes)]);
160+
}
161+
$this->extensionManager->discoverModules();
162+
}
163+
}
164+
$this->themeHandler->install($themes);
165+
166+
$unInstalledThemes = $this->validator->getUninstalledThemes($themes);
167+
168+
if (!$unInstalledThemes) {
169+
return 0;
170+
}else{
171+
return $this->setInfoMessage('commands.theme.install.messages.theme-success', $missingThemes);
172+
}
173+
}
131174

132175
protected function calculateDependencies($modules)
133176
{
@@ -303,7 +346,7 @@ private function getExtractPath($type)
303346
case 'module':
304347
return 'modules/contrib';
305348
case 'theme':
306-
return 'themes';
349+
return 'themes/contrib';
307350
case 'profile':
308351
return 'profiles';
309352
case 'core':

src/Command/Theme/InstallCommand.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,23 @@
1212
use Symfony\Component\Console\Input\InputInterface;
1313
use Symfony\Component\Console\Output\OutputInterface;
1414
use Drupal\Core\Config\UnmetDependenciesException;
15+
use Drupal\Console\Command\Shared\ProjectDownloadTrait;
16+
use Drupal\Console\Core\Command\Command;
17+
use Drupal\Console\Command\Shared\ModuleTrait;
18+
use Drupal\Console\Utils\Site;
19+
use Drupal\Console\Utils\Validator;
20+
use Drupal\Core\Extension\ModuleInstallerInterface;
21+
use Drupal\Console\Utils\DrupalApi;
22+
use Drupal\Console\Extension\Manager;
23+
use Drupal\Console\Core\Utils\ChainQueue;
1524

1625
class InstallCommand extends ThemeBaseCommand
1726
{
27+
use ProjectDownloadTrait;
28+
use ModuleTrait;
29+
/**
30+
* {@inheritdoc}
31+
*/
1832
protected function configure()
1933
{
2034
$this
@@ -88,7 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
88102
if (count($this->getUnavailableThemes()) > 1) {
89103
$this->setErrorMessage('commands.theme.install.messages.themes-missing', $this->getUnavailableThemes());
90104
} else {
91-
$this->setErrorMessage('commands.theme.install.messages.themes-missing', $this->getUnavailableThemes());
105+
$resultList = $this->downloadThemes($theme, $default);
92106
}
93107
}
94108

src/Command/Theme/ThemeBaseCommand.php

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
use Drupal\Core\Config\UnmetDependenciesException;
1313
use Drupal\Core\Extension\ThemeHandlerInterface;
1414
use Drupal\Console\Core\Utils\ChainQueue;
15-
15+
use Drupal\Console\Utils\Site;
16+
use Drupal\Console\Utils\Validator;
17+
use Drupal\Core\Extension\ModuleInstallerInterface;
18+
use Drupal\Console\Utils\DrupalApi;
19+
use Drupal\Console\Extension\Manager;
1620
/**
1721
* Class ThemeBaseCommand
1822
*
@@ -34,12 +38,34 @@ class ThemeBaseCommand extends Command
3438
* @var ChainQueue
3539
*/
3640
protected $chainQueue;
37-
41+
/**
42+
* @var Site
43+
*/
44+
protected $site;
45+
/**
46+
* @var Validator
47+
*/
48+
protected $validator;
49+
/**
50+
* @var ModuleInstaller
51+
*/
52+
protected $moduleInstaller;
53+
/**
54+
* @var DrupalApi
55+
*/
56+
protected $drupalApi;
57+
/**
58+
* @var Manager
59+
*/
60+
protected $extensionManager;
61+
/**
62+
* @var string
63+
*/
64+
protected $appRoot;
3865
/**
3966
* @var array
4067
*/
4168
protected $themes;
42-
4369
/**
4470
* @var array
4571
*/
@@ -61,15 +87,32 @@ class ThemeBaseCommand extends Command
6187
* @param ConfigFactory $configFactory
6288
* @param ThemeHandler $themeHandler
6389
* @param ChainQueue $chainQueue
90+
* @param Site $site
91+
* @param Validator $validator
92+
* @param ModuleInstaller $moduleInstaller
93+
* @param DrupalApi $drupalApi
94+
* @param Manager $extensionManager
95+
* @param $appRoot
6496
*/
6597
public function __construct(
6698
ConfigFactoryInterface $configFactory,
6799
ThemeHandlerInterface $themeHandler,
68-
ChainQueue $chainQueue
100+
ChainQueue $chainQueue,
101+
Site $site,
102+
Validator $validator,
103+
ModuleInstallerInterface $moduleInstaller,
104+
DrupalApi $drupalApi,
105+
Manager $extensionManager, $appRoot
69106
) {
70107
$this->configFactory = $configFactory;
71108
$this->themeHandler = $themeHandler;
72109
$this->chainQueue = $chainQueue;
110+
$this->site = $site;
111+
$this->validator = $validator;
112+
$this->moduleInstaller = $moduleInstaller;
113+
$this->drupalApi = $drupalApi;
114+
$this->extensionManager = $extensionManager;
115+
$this->appRoot = $appRoot;
73116
$this->themes = $this->themeHandler->rebuildThemeData();
74117
parent::__construct();
75118
}

src/Utils/Validator.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,23 @@ public function getMissingModules($moduleList)
314314

315315
return array_diff($moduleList, $modules);
316316
}
317+
318+
/**
319+
* @param $moduleList
320+
* @return array
321+
*/
322+
public function getMissingThemes($moduleList)
323+
{
324+
325+
$modules = $this->extensionManager->discoverThemes()
326+
->showInstalled()
327+
->showUninstalled()
328+
->showNoCore()
329+
->showCore()
330+
->getList(true);
317331

332+
return array_diff($moduleList, $modules);
333+
}
318334
/**
319335
* @param $moduleList
320336
* @return array

0 commit comments

Comments
 (0)