Skip to content

Commit 6806bb7

Browse files
authored
Allow projects to specify which user id to pass to drush for login. (#168)
1 parent 0503956 commit 6806bb7

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

.sites.config.example.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
default:
33
database_s3_bucket: S3_BUCKET_NAME
44
database_s3_key_prefix_string: prod-db-prefix
5+
drupal_user_login_uid: 108
56
theme_build:
67
- theme_path: web/themes/custom/theme1
78
theme_build_commands:

src/Robo/Plugin/Commands/DevelopmentModeBaseCommands.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,12 @@ public function drupalLoginLink(
192192
string $siteDir = 'default',
193193
): Result {
194194
$this->io()->section("create login link.");
195+
$uid = $this->getDrupalSiteAdminUid(siteName: $siteDir);
195196
return $this->taskExec($environmentType)
196197
->arg('drush')
197198
->arg("@$siteDir.$environmentType")
198199
->arg('user:login')
200+
->option("--uid=$uid")
199201
->dir("$this->drupalRoot/sites/$siteDir")
200202
->run();
201203
}

src/Robo/Plugin/Traits/SitesConfigTrait.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,17 @@ protected function getSiteConfig(string $siteName = 'default'): array
7878
* The site configuration key to load.
7979
* @param string $siteName
8080
* The site name.
81+
* @param bool $required
82+
* Whether the config item is expected to always be present.
8183
*/
82-
public function getSiteConfigItem(string $key, string $siteName = 'default'): mixed
84+
public function getSiteConfigItem(string $key, string $siteName = 'default', bool $required = true): mixed
8385
{
8486
$siteConfig = $this->getSiteConfig(siteName: $siteName);
8587
if (!isset($siteConfig[$key])) {
86-
throw new TaskException($this, "Key $key not found for '$siteName' in $this->sitesConfigFile.");
88+
if ($required) {
89+
throw new TaskException($this, "Key $key not found for '$siteName' in $this->sitesConfigFile.");
90+
}
91+
return null;
8792
}
8893
return $siteConfig[$key];
8994
}
@@ -99,4 +104,24 @@ protected function writeSitesConfig(array $sitesConfig): void
99104
ksort($sitesConfig);
100105
file_put_contents($this->sitesConfigFile, Yaml::dump($sitesConfig));
101106
}
107+
108+
/**
109+
* Get the Drupal site admin user ID.
110+
*
111+
* @param string $siteName
112+
* The site name.
113+
*
114+
* @return int
115+
* The Drupal admin user ID.
116+
*/
117+
protected function getDrupalSiteAdminUid(string $siteName = 'default'): int
118+
{
119+
return $this->getSiteConfigItem(
120+
key: 'drupal_user_login_uid',
121+
siteName: $siteName,
122+
required: false,
123+
// @todo: Replace the use of '1' with a constant once we drop PHP
124+
// 8.1 support.
125+
) ?? 1;
126+
}
102127
}

0 commit comments

Comments
 (0)