Skip to content

Commit

Permalink
VATEAM-90582: Add 21-4140 Digital Form to seed script (#19047)
Browse files Browse the repository at this point in the history
* Add create_digital_forms

* Add 21-4140 to digital forms script

* Switch includeDob to snake case
  • Loading branch information
derekhouck authored and ryguyk committed Dec 12, 2024
1 parent 0ed827f commit cca5222
Showing 1 changed file with 44 additions and 16 deletions.
60 changes: 44 additions & 16 deletions scripts/content/digital-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,76 @@ function run() {
$env = getenv('CMS_ENVIRONMENT_TYPE') ?: 'ci';
exit_if_not_local_or_tugboat($env);

create_digital_form();
create_digital_forms();
}

/**
* Creates a Digital Form with hard-coded values.
*
* @param array $values
* The Node values.
* @param array $steps
* An array of arrays. The inner arrays contain step values.
*/
function create_digital_form() {
$digital_form = Node::create([
function create_digital_form(
array $values = [
'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));
],
array $steps = [
[],
['title' => 'Step without Date of Birth', 'include_dob' => FALSE],
],
) {
$digital_form = Node::create($values);

foreach ($steps as $step_values) {
$digital_form->field_chapters->appendItem(create_step($step_values));
}

save_node_revision($digital_form, 'Created by the content script', TRUE);
}

/**
* Creates test Digital Forms.
*/
function create_digital_forms() {
$form_21_4140 = [
'type' => 'digital_form',
'title' => 'Employment Questionnaire',
'field_va_form_number' => '21-4140',
'field_omb_number' => '2900-0079',
'moderation_state' => 'published',
];
$form_21_4140_steps = [
['title' => "Veteran's personal information", 'include_dob' => TRUE],
];

create_digital_form();
create_digital_form($form_21_4140, $form_21_4140_steps);
}

/**
* 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?
* @param array $values
* The values for the Paragraph.
*
* @return \Drupal\paragraphs\Entity\Paragraph
* The created Step.
*/
function create_step(
string $title = 'Script Generated Step',
bool $includeDob = TRUE,
array $values = [],
): Paragraph {
return Paragraph::create([
'type' => 'digital_form_name_and_date_of_bi',
'field_title' => $title,
'field_include_date_of_birth' => $includeDob,
'field_title' => $values['title'] ?? 'Script Generated Step',
'field_include_date_of_birth' => $values['include_dob'] ?? TRUE,
]);
}

0 comments on commit cca5222

Please sign in to comment.