Skip to content

Commit 1e2b79e

Browse files
committed
[#2340] Moved demo code from ys_base to new ys_demo module.
1 parent a990413 commit 1e2b79e

466 files changed

Lines changed: 1772 additions & 735 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vortex/docs/content/drupal/provision-example.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ if echo "${environment}" | grep -q -e dev -e stage -e ci -e local; then
3737

3838
# 👇 Enable custom site modules and run its deployment hooks.
3939
task "Installing custom site modules."
40-
drush pm:install ys_base ys_search
40+
drush pm:install ys_base
41+
drush pm:install ys_search
42+
drush pm:install ys_demo
4143

4244
# 👇 Conditionally perform an action if this is a "fresh" database.
4345
if [ "${VORTEX_PROVISION_OVERRIDE_DB:-0}" = "1" ]; then
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DrevOps\VortexInstaller\Prompts\Handlers;
6+
7+
use DrevOps\VortexInstaller\Utils\File;
8+
use DrevOps\VortexInstaller\Utils\Tui;
9+
10+
class CustomModules extends AbstractHandler {
11+
12+
const BASE = 'base';
13+
14+
const DEMO = 'demo';
15+
16+
const SEARCH = 'search';
17+
18+
/**
19+
* {@inheritdoc}
20+
*/
21+
public function label(): string {
22+
return 'Custom modules';
23+
}
24+
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
public static function description(array $responses): ?string {
29+
$base = Tui::bold('Base');
30+
$demo = Tui::bold('Demo');
31+
$search = Tui::bold('Search');
32+
33+
return <<<DOC
34+
Select which custom modules to include in your project:
35+
36+
{$base}
37+
Starter module with common site utilities (mail handling,
38+
deploy hooks) and test scaffolding for Unit, Kernel,
39+
Functional, and FunctionalJavascript tests.
40+
41+
{$search}
42+
Custom Solr search integration module. Requires the Solr
43+
service to be selected.
44+
45+
{$demo}
46+
Demonstrates how Vortex tooling works: includes a counter
47+
block with CSS/JS, PHPUnit example tests across all test
48+
types, and a Behat feature. Safe to remove on real projects.
49+
DOC;
50+
}
51+
52+
/**
53+
* {@inheritdoc}
54+
*/
55+
public function hint(array $responses): ?string {
56+
return 'Use ⬆, ⬇ and Space bar to select one or more modules.';
57+
}
58+
59+
/**
60+
* {@inheritdoc}
61+
*/
62+
public function options(array $responses): ?array {
63+
return [
64+
self::BASE => 'Base - starter module with utilities and test scaffolding',
65+
self::SEARCH => 'Search - custom Solr search integration',
66+
self::DEMO => 'Demo - counter block and example tests to demonstrate tooling',
67+
];
68+
}
69+
70+
/**
71+
* {@inheritdoc}
72+
*/
73+
public function default(array $responses): null|string|bool|array {
74+
return [self::BASE, self::SEARCH, self::DEMO];
75+
}
76+
77+
/**
78+
* {@inheritdoc}
79+
*/
80+
public function discover(): null|string|bool|array {
81+
if (!$this->isInstalled()) {
82+
return NULL;
83+
}
84+
85+
// Discover the module prefix from the existing codebase.
86+
$prefix = $this->discoverModulePrefix();
87+
88+
if ($prefix === NULL) {
89+
return NULL;
90+
}
91+
92+
$modules = [];
93+
94+
$module_dir = $this->dstDir . '/' . $this->webroot . '/modules/custom';
95+
96+
if (is_dir($module_dir . '/' . $prefix . '_base')) {
97+
$modules[] = self::BASE;
98+
}
99+
100+
if (is_dir($module_dir . '/' . $prefix . '_demo')) {
101+
$modules[] = self::DEMO;
102+
}
103+
104+
if (is_dir($module_dir . '/' . $prefix . '_search')) {
105+
$modules[] = self::SEARCH;
106+
}
107+
108+
sort($modules);
109+
110+
return $modules;
111+
}
112+
113+
/**
114+
* {@inheritdoc}
115+
*/
116+
public function process(): void {
117+
$selected = $this->getResponseAsArray();
118+
$t = $this->tmpDir;
119+
$w = $this->webroot;
120+
121+
// Safety net: if search was selected but Solr service was not, force-remove
122+
// search module since it cannot function without Solr.
123+
if (in_array(self::SEARCH, $selected) && isset($this->responses[Services::id()])) {
124+
$services = $this->responses[Services::id()];
125+
if (is_array($services) && !in_array(Services::SOLR, $services)) {
126+
$selected = array_values(array_diff($selected, [self::SEARCH]));
127+
}
128+
}
129+
130+
if (!in_array(self::BASE, $selected)) {
131+
File::removeTokenAsync('CUSTOM_MODULE_BASE');
132+
133+
$locations = [
134+
$t . sprintf('/%s/modules/custom/*_base', $w),
135+
$t . sprintf('/%s/sites/all/modules/custom/*_base', $w),
136+
$t . sprintf('/%s/profiles/*/modules/*_base', $w),
137+
$t . sprintf('/%s/profiles/*/modules/custom/*_base', $w),
138+
$t . sprintf('/%s/profiles/custom/*/modules/*_base', $w),
139+
$t . sprintf('/%s/profiles/custom/*/modules/custom/*_base', $w),
140+
];
141+
142+
$path = File::findMatchingPath($locations);
143+
if ($path) {
144+
File::remove($path);
145+
}
146+
}
147+
148+
if (!in_array(self::DEMO, $selected)) {
149+
File::removeTokenAsync('CUSTOM_MODULE_DEMO');
150+
151+
$locations = [
152+
$t . sprintf('/%s/modules/custom/*_demo', $w),
153+
$t . sprintf('/%s/sites/all/modules/custom/*_demo', $w),
154+
$t . sprintf('/%s/profiles/*/modules/*_demo', $w),
155+
$t . sprintf('/%s/profiles/*/modules/custom/*_demo', $w),
156+
$t . sprintf('/%s/profiles/custom/*/modules/*_demo', $w),
157+
$t . sprintf('/%s/profiles/custom/*/modules/custom/*_demo', $w),
158+
];
159+
160+
$path = File::findMatchingPath($locations);
161+
if ($path) {
162+
File::remove($path);
163+
}
164+
165+
File::remove($t . '/tests/behat/features/counter.feature');
166+
}
167+
168+
if (!in_array(self::SEARCH, $selected)) {
169+
File::removeTokenAsync('CUSTOM_MODULE_SEARCH');
170+
171+
$locations = [
172+
$t . sprintf('/%s/modules/custom/*_search', $w),
173+
$t . sprintf('/%s/sites/all/modules/custom/*_search', $w),
174+
$t . sprintf('/%s/profiles/*/modules/*_search', $w),
175+
$t . sprintf('/%s/profiles/*/modules/custom/*_search', $w),
176+
$t . sprintf('/%s/profiles/custom/*/modules/*_search', $w),
177+
$t . sprintf('/%s/profiles/custom/*/modules/custom/*_search', $w),
178+
];
179+
180+
$path = File::findMatchingPath($locations);
181+
if ($path) {
182+
File::remove($path);
183+
}
184+
}
185+
}
186+
187+
/**
188+
* Discover the module prefix from the existing codebase.
189+
*
190+
* @return string|null
191+
* The discovered module prefix, or NULL if not found.
192+
*/
193+
protected function discoverModulePrefix(): ?string {
194+
$locations = [
195+
$this->dstDir . sprintf('/%s/modules/custom/*_base', $this->webroot),
196+
$this->dstDir . sprintf('/%s/modules/custom/*_core', $this->webroot),
197+
$this->dstDir . sprintf('/%s/sites/all/modules/custom/*_base', $this->webroot),
198+
$this->dstDir . sprintf('/%s/sites/all/modules/custom/*_core', $this->webroot),
199+
];
200+
201+
$path = File::findMatchingPath($locations);
202+
203+
return empty($path) ? NULL : str_replace(['_base', '_core'], '', basename($path));
204+
}
205+
206+
}
207+

.vortex/installer/src/Prompts/Handlers/ModulePrefix.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,26 @@ public function process(): void {
9595
$w = $this->webroot;
9696

9797
File::replaceContentAsync([
98+
'ys_demo' => $v . '_demo',
99+
'ys-demo' => Converter::kebab($v) . '-demo',
98100
'ys_base' => $v . '_base',
99101
'ys-base' => Converter::kebab($v) . '-base',
100102
'ys_search' => $v . '_search',
101103
'ys-search' => Converter::kebab($v) . '-search',
104+
'YsDemo' => Converter::pascal($v) . 'Demo',
102105
'YsBase' => Converter::pascal($v) . 'Base',
103106
'YsSearch' => Converter::pascal($v) . 'Search',
104107
'YSBASE' => Converter::cobol($v),
105108
'YSSEARCH' => Converter::cobol($v),
106109
]);
107110

111+
File::renameInDir($t . sprintf('/%s/modules/custom', $w), 'ys_demo', $v . '_demo');
112+
File::renameInDir($t . sprintf('/%s/modules/custom', $w), 'ys-demo', Converter::kebab($v) . '-demo');
108113
File::renameInDir($t . sprintf('/%s/modules/custom', $w), 'ys_base', $v . '_base');
109114
File::renameInDir($t . sprintf('/%s/modules/custom', $w), 'ys-base', Converter::kebab($v) . '-base');
110115
File::renameInDir($t . sprintf('/%s/modules/custom', $w), 'ys_search', $v . '_search');
111116
File::renameInDir($t . sprintf('/%s/modules/custom', $w), 'ys-search', Converter::kebab($v) . '-search');
117+
File::renameInDir($t . sprintf('/%s/modules/custom', $w), 'YsDemo', Converter::pascal($v) . 'Demo');
112118
File::renameInDir($t . sprintf('/%s/modules/custom', $w), 'YsBase', Converter::pascal($v) . 'Base');
113119
File::renameInDir($t . sprintf('/%s/modules/custom', $w), 'YsSearch', Converter::pascal($v) . 'Search');
114120
File::renameInDir($t . sprintf('/%s/sites/default/includes', $w), 'ys_base', $v . '_base');

.vortex/installer/src/Prompts/Handlers/Services.php

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,42 @@ public function hint(array $responses): ?string {
3333
* {@inheritdoc}
3434
*/
3535
public function options(array $responses): ?array {
36-
return [
36+
$options = [
3737
self::CLAMAV => 'ClamAV',
3838
self::SOLR => 'Solr',
3939
self::REDIS => 'Redis',
4040
];
41+
42+
// Hide Solr if the search custom module is not selected and Solr is not
43+
// already discovered in the existing codebase.
44+
if (isset($responses[CustomModules::id()])) {
45+
$custom_modules = $responses[CustomModules::id()];
46+
if (is_array($custom_modules) && !in_array(CustomModules::SEARCH, $custom_modules)) {
47+
// Check if Solr is discovered in the existing docker-compose.yml.
48+
$discovered = $this->discover();
49+
$solr_discovered = is_array($discovered) && in_array(self::SOLR, $discovered);
50+
if (!$solr_discovered) {
51+
unset($options[self::SOLR]);
52+
}
53+
}
54+
}
55+
56+
return $options;
4157
}
4258

4359
/**
4460
* {@inheritdoc}
4561
*/
4662
public function default(array $responses): null|string|bool|array {
47-
return [self::CLAMAV, self::REDIS, self::SOLR];
63+
$defaults = [self::CLAMAV, self::REDIS, self::SOLR];
64+
65+
// Filter defaults to only include available options.
66+
$options = $this->options($responses);
67+
if (is_array($options)) {
68+
$defaults = array_values(array_intersect($defaults, array_keys($options)));
69+
}
70+
71+
return $defaults;
4872
}
4973

5074
/**
@@ -129,21 +153,6 @@ public function process(): void {
129153
File::removeLineInFile($t . DIRECTORY_SEPARATOR . '.ahoy.yml', 'VORTEX_HOST_SOLR_PORT=$(docker compose port solr 8983 2>/dev/null | cut -d : -f 2) && \\');
130154
// @todo Remove after 25.10.0 release.
131155
File::removeLineInFile($t . DIRECTORY_SEPARATOR . '.ahoy.yml', 'VORTEX_HOST_SOLR_PORT=$(docker compose port solr 8983 2>/dev/null | cut -d : -f 2) \\');
132-
File::replaceContentInFile($t . DIRECTORY_SEPARATOR . 'scripts/custom/provision-10-example.sh', 'drush pm:install ys_base ys_search', 'drush pm:install ys_base');
133-
134-
$locations = [
135-
$t . sprintf('/%s/modules/custom/*_search', $w),
136-
$t . sprintf('/%s/sites/all/modules/custom/*_search', $w),
137-
$t . sprintf('/%s/profiles/*/modules/*_search', $w),
138-
$t . sprintf('/%s/profiles/*/modules/custom/*_search', $w),
139-
$t . sprintf('/%s/profiles/custom/*/modules/*_search', $w),
140-
$t . sprintf('/%s/profiles/custom/*/modules/custom/*_search', $w),
141-
];
142-
143-
$path = File::findMatchingPath($locations);
144-
if ($path) {
145-
File::remove($path);
146-
}
147156
}
148157

149158
if (!in_array(self::REDIS, $v)) {

.vortex/installer/src/Prompts/PromptManager.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use DrevOps\VortexInstaller\Prompts\Handlers\AssignAuthorPr;
1010
use DrevOps\VortexInstaller\Prompts\Handlers\CiProvider;
1111
use DrevOps\VortexInstaller\Prompts\Handlers\CodeProvider;
12+
use DrevOps\VortexInstaller\Prompts\Handlers\CustomModules;
1213
use DrevOps\VortexInstaller\Prompts\Handlers\DatabaseDownloadSource;
1314
use DrevOps\VortexInstaller\Prompts\Handlers\DatabaseImage;
1415
use DrevOps\VortexInstaller\Prompts\Handlers\DependencyUpdatesProvider;
@@ -64,7 +65,7 @@ class PromptManager {
6465
*
6566
* Used to display the progress of the prompts.
6667
*/
67-
const TOTAL_RESPONSES = 31;
68+
const TOTAL_RESPONSES = 32;
6869

6970
/**
7071
* Array of responses.
@@ -141,6 +142,7 @@ public function runPrompts(): void {
141142
)
142143
->add(fn(array $r, $pr, $n): mixed => $this->prompt(Modules::class, $r), Modules::id())
143144
->add(fn(array $r, $pr, $n): mixed => $this->prompt(ModulePrefix::class, $r), ModulePrefix::id())
145+
->add(fn(array $r, $pr, $n): mixed => $this->prompt(CustomModules::class, $r), CustomModules::id())
144146
->add(
145147
fn(array $r, $pr, $n): string => $this->resolveOrPrompt(Theme::id(), $r, fn(): mixed => $this->prompt(Theme::class)),
146148
Theme::id()
@@ -303,6 +305,7 @@ public function runProcessors(): void {
303305
Profile::id(),
304306
Domain::id(),
305307
HostingProjectName::id(),
308+
CustomModules::id(),
306309
ModulePrefix::id(),
307310
ThemeCustom::id(),
308311
Theme::id(),
@@ -428,6 +431,7 @@ public function getResponsesSummary(): array {
428431
$values['Webroot'] = $responses[Webroot::id()];
429432
$values['Profile'] = $responses[Profile::id()];
430433
$values['Module prefix'] = $responses[ModulePrefix::id()];
434+
$values['Custom modules'] = Converter::toList($responses[CustomModules::id()], ', ');
431435
$values['Theme machine name'] = $responses[Theme::id()] ?? '<empty>';
432436

433437
$values['Code repository'] = Tui::LIST_SECTION_TITLE;

.vortex/installer/tests/Fixtures/handler_process/_baseline/scripts/custom/provision-10-example.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ if echo "${environment}" | grep -q -e dev -e stage -e ci -e local; then
5959

6060
drush pm:install sw_search
6161

62+
drush pm:install sw_demo
63+
6264
task "Running deployment hooks."
6365
drush deploy:hook
6466

0 commit comments

Comments
 (0)