From a58e4e18156a541ec2006e5f74838a0b5171a4c5 Mon Sep 17 00:00:00 2001 From: Derek Houck Date: Mon, 26 Aug 2024 10:55:02 -0500 Subject: [PATCH] VATEAM-88658: Script to add Digital Forms test data (#19025) * WIP: Create digital form script * Add steps * Rename exit_if_wrong_env --- scripts/content/digital-forms.php | 68 +++++++++++++++++++ scripts/content/script-library.php | 15 +++- .../VACMS-17969-vba-test-data-processor.php | 5 +- 3 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 scripts/content/digital-forms.php diff --git a/scripts/content/digital-forms.php b/scripts/content/digital-forms.php new file mode 100644 index 0000000000..cc22b4f1ed --- /dev/null +++ b/scripts/content/digital-forms.php @@ -0,0 +1,68 @@ + 'digital_form', + 'title' => 'Script Generated Digital Form', + 'field_va_form_number' => '123456789', + 'field_omb_number' => '1234-5678', + 'moderation_state' => 'published', + ]); + $digital_form->field_chapters->appendItem(create_step()); + $digital_form + ->field_chapters + ->appendItem(create_step('Step without Date of Birth', FALSE)); + save_node_revision($digital_form, 'Created by the content script', TRUE); +} + +/** + * Creates a Digital Form Step. + * + * For now, this only creates the Name and Date of Birth step. + * That will change as more patterns are added. + * + * @param string $title + * The step title. + * @param bool $includeDob + * Should the step include the date of birth field? + * + * @return \Drupal\paragraphs\Entity\Paragraph + * The created Step. + */ +function create_step( + string $title = 'Script Generated Step', + bool $includeDob = TRUE, +): Paragraph { + return Paragraph::create([ + 'type' => 'digital_form_name_and_date_of_bi', + 'field_title' => $title, + 'field_include_date_of_birth' => $includeDob, + ]); +} diff --git a/scripts/content/script-library.php b/scripts/content/script-library.php index e7d55cca42..a19bedfd1f 100644 --- a/scripts/content/script-library.php +++ b/scripts/content/script-library.php @@ -19,7 +19,7 @@ use Drupal\user\UserStorageInterface; use Psr\Log\LogLevel; -const CMS_MIGRATOR_ID = 1317; +const CMS_MIGRATOR_ID = 1317; // phpcs:ignore /** * Log a message to stdout. @@ -46,6 +46,19 @@ function entity_type_manager(): EntityTypeManagerInterface { return $entity_type_manager; } +/** + * Exit if script is run in an environment other than local or tugboat. + * + * @param string $env + * The CMS environment. + */ +function exit_if_not_local_or_tugboat(string $env) { + if ($env !== 'local' && $env !== 'tugboat') { + echo "This script can only be run on local or Tugboat environments.\n"; + exit(); + } +} + /** * Get the node storage. * diff --git a/scripts/content/vacms-17969/VACMS-17969-vba-test-data-processor.php b/scripts/content/vacms-17969/VACMS-17969-vba-test-data-processor.php index 6e57b04f8a..e4393eb5cc 100644 --- a/scripts/content/vacms-17969/VACMS-17969-vba-test-data-processor.php +++ b/scripts/content/vacms-17969/VACMS-17969-vba-test-data-processor.php @@ -20,10 +20,7 @@ */ function run() { $env = getenv('CMS_ENVIRONMENT_TYPE') ?: 'ci'; - if ($env !== 'local' && $env !== 'tugboat') { - echo "This script can only be run on local or Tugboat environments.\n"; - exit(); - } + exit_if_not_local_or_tugboat($env); process_csv_file(__DIR__ . '/VACMS-17969-vba-test-data-source-services.csv', 'create_vba_facility_service_node'); process_csv_file(__DIR__ . '/VACMS-17969-vba-test-data-source-facilities.csv',