diff --git a/.homepage-uuid b/.homepage-uuid new file mode 100644 index 00000000..639898b6 --- /dev/null +++ b/.homepage-uuid @@ -0,0 +1 @@ +df0e2d62-c293-42be-8165-84542c35129d \ No newline at end of file diff --git a/orch/deploy_install.sh b/orch/deploy_install.sh index e31999b6..369b0a48 100755 --- a/orch/deploy_install.sh +++ b/orch/deploy_install.sh @@ -59,4 +59,7 @@ fi # Clear cache after installation drush cr +# Set the homepage. Custom functionality for Digital.gov. +drush set-hp -y + ./orch/show_file.sh $0 end diff --git a/web/modules/custom/default_content_config/drush.services.yml b/web/modules/custom/default_content_config/drush.services.yml new file mode 100644 index 00000000..54955743 --- /dev/null +++ b/web/modules/custom/default_content_config/drush.services.yml @@ -0,0 +1,6 @@ +services: + init.commands: + class: \Drupal\default_content_config\Commands\CustomCommands + arguments: ["@config.factory", "@entity_type.manager"] + tags: + - { name: drush.command } diff --git a/web/modules/custom/default_content_config/src/Commands/CustomCommands.php b/web/modules/custom/default_content_config/src/Commands/CustomCommands.php new file mode 100644 index 00000000..d41d8f46 --- /dev/null +++ b/web/modules/custom/default_content_config/src/Commands/CustomCommands.php @@ -0,0 +1,79 @@ +configFactory = $configFactory; + $this->entityTypeManager = $entityTypeManager; + } + + /** + * A custom Drush command to set the homepage URL post site install. + * + * @command drush-command:set-homepage + * + * @aliases set-hp + */ + public function setHomepage(array $options = []): void { + $no_interaction = FALSE; + if ($options['no-interaction'] || $options['yes']) { + $no_interaction = TRUE; + } + $homepage_uuid_file = '../.homepage-uuid'; + $homepage_uuid = file_get_contents($homepage_uuid_file); + if (!$homepage_uuid) { + if ($no_interaction) { + $this->io()->warning(dt('Your homepage has not been set yet, do so by calling drush set-hp')); + return; + } + else { + $homepage_uuid = $this->ask('What is the UUID of your homepage node?'); + if (!$homepage_uuid) { + throw new \Exception(dt('A homepage is required')); + } + file_put_contents($homepage_uuid_file, $homepage_uuid); + } + } + + $nodes = $this->entityTypeManager->getStorage('node')->loadByProperties(['uuid' => $homepage_uuid]); + if (empty($nodes)) { + file_put_contents($homepage_uuid_file, ''); + throw new \Exception(dt('Unable to find a node for homepage by UUID ') . $homepage_uuid); + } + /** @var \Drupal\node\NodeInterface $node */ + $node = reset($nodes); + $homepage_url = '/node/' . $node->id(); + $this->configFactory->getEditable('system.site') + ->set('page.front', $homepage_url) + ->save(); + $this->io()->success(dt('Homepage has been set to ') . $homepage_url); + } + +}