-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VATEAM-88658: Script to add Digital Forms test data (#19025)
* WIP: Create digital form script * Add steps * Rename exit_if_wrong_env
- Loading branch information
1 parent
24e69b5
commit af73e95
Showing
3 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Creates Digital Form test data for local and Tugboat environments. | ||
* | ||
* !!!! DO NOT RUN ON PROD !!!! | ||
*/ | ||
|
||
use Drupal\node\Entity\Node; | ||
use Drupal\paragraphs\Entity\Paragraph; | ||
|
||
require_once __DIR__ . '/script-library.php'; | ||
|
||
run(); | ||
|
||
/** | ||
* Executes the script. | ||
*/ | ||
function run() { | ||
$env = getenv('CMS_ENVIRONMENT_TYPE') ?: 'ci'; | ||
exit_if_not_local_or_tugboat($env); | ||
|
||
create_digital_form(); | ||
} | ||
|
||
/** | ||
* Creates a Digital Form with hard-coded values. | ||
*/ | ||
function create_digital_form() { | ||
$digital_form = Node::create([ | ||
'type' => '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, | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters