diff --git a/.sites.config.example.yml b/.sites.config.example.yml index 558eb8f..057d131 100644 --- a/.sites.config.example.yml +++ b/.sites.config.example.yml @@ -2,6 +2,7 @@ default: database_s3_bucket: S3_BUCKET_NAME database_s3_key_prefix_string: prod-db-prefix + drupal_user_login_uid: 108 theme_build: - theme_path: web/themes/custom/theme1 theme_build_commands: diff --git a/src/Robo/Plugin/Commands/DevelopmentModeBaseCommands.php b/src/Robo/Plugin/Commands/DevelopmentModeBaseCommands.php index 0aab100..37f34d8 100644 --- a/src/Robo/Plugin/Commands/DevelopmentModeBaseCommands.php +++ b/src/Robo/Plugin/Commands/DevelopmentModeBaseCommands.php @@ -192,10 +192,12 @@ public function drupalLoginLink( string $siteDir = 'default', ): Result { $this->io()->section("create login link."); + $uid = $this->getDrupalSiteAdminUid(siteName: $siteDir); return $this->taskExec($environmentType) ->arg('drush') ->arg("@$siteDir.$environmentType") ->arg('user:login') + ->option("--uid=$uid") ->dir("$this->drupalRoot/sites/$siteDir") ->run(); } diff --git a/src/Robo/Plugin/Traits/SitesConfigTrait.php b/src/Robo/Plugin/Traits/SitesConfigTrait.php index 22f16bb..be0210c 100644 --- a/src/Robo/Plugin/Traits/SitesConfigTrait.php +++ b/src/Robo/Plugin/Traits/SitesConfigTrait.php @@ -78,12 +78,17 @@ protected function getSiteConfig(string $siteName = 'default'): array * The site configuration key to load. * @param string $siteName * The site name. + * @param bool $required + * Whether the config item is expected to always be present. */ - public function getSiteConfigItem(string $key, string $siteName = 'default'): mixed + public function getSiteConfigItem(string $key, string $siteName = 'default', bool $required = true): mixed { $siteConfig = $this->getSiteConfig(siteName: $siteName); if (!isset($siteConfig[$key])) { - throw new TaskException($this, "Key $key not found for '$siteName' in $this->sitesConfigFile."); + if ($required) { + throw new TaskException($this, "Key $key not found for '$siteName' in $this->sitesConfigFile."); + } + return null; } return $siteConfig[$key]; } @@ -99,4 +104,24 @@ protected function writeSitesConfig(array $sitesConfig): void ksort($sitesConfig); file_put_contents($this->sitesConfigFile, Yaml::dump($sitesConfig)); } + + /** + * Get the Drupal site admin user ID. + * + * @param string $siteName + * The site name. + * + * @return int + * The Drupal admin user ID. + */ + protected function getDrupalSiteAdminUid(string $siteName = 'default'): int + { + return $this->getSiteConfigItem( + key: 'drupal_user_login_uid', + siteName: $siteName, + required: false, + // @todo: Replace the use of '1' with a constant once we drop PHP + // 8.1 support. + ) ?? 1; + } }