Skip to content

Commit dd04e63

Browse files
committed
Adds "Your personal information" step when the form is first created in Form Builder.
1 parent a2db291 commit dd04e63

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

docroot/modules/custom/va_gov_form_builder/src/Form/FormInfo.php

+27-1
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,11 @@ protected function setDigitalFormFromFormState(array &$form, FormStateInterface
133133
/*
134134
* This form is creating a new Digital Form.
135135
*
136-
* Create the new Digital Form with the fields from this form.
136+
* We need to create a new Digital Form by doing two things:
137+
* 1. Create the new Digital Form with the fields from this form.
138+
* 2. Add default "Your personal information" step.
137139
*/
140+
// 1. Create the new Digital Form with the fields from this form.
138141
$node = $this->entityTypeManager->getStorage('node')->create([
139142
'type' => 'digital_form',
140143
'title' => $title,
@@ -143,6 +146,29 @@ protected function setDigitalFormFromFormState(array &$form, FormStateInterface
143146
'field_respondent_burden' => $respondentBurden,
144147
'field_expiration_date' => $expirationDate,
145148
]);
149+
150+
// 2. Add "Your personal information" step (paragraph).
151+
// This step contains two sub-steps:
152+
// --> Name and date of birth
153+
$nameAndDobParagraph = $this->entityTypeManager->getStorage('paragraph')->create([
154+
'type' => 'digital_form_name_and_date_of_bi',
155+
'field_title' => 'Name and date of birth',
156+
'field_include_date_of_birth' => TRUE,
157+
]);
158+
// --> Identification information
159+
$identificationInfo = $this->entityTypeManager->getStorage('paragraph')->create([
160+
'type' => 'digital_form_identification_info',
161+
'field_title' => 'Identifying information',
162+
'field_include_veteran_s_service' => TRUE,
163+
]);
164+
// Your personal information wraps both.
165+
$yourPersonalInformation = $this->entityTypeManager->getStorage('paragraph')->create([
166+
'type' => 'digital_form_your_personal_info',
167+
'field_name_and_date_of_birth' => $nameAndDobParagraph,
168+
'field_identification_information' => $identificationInfo,
169+
]);
170+
$node->get('field_chapters')->appendItem($yourPersonalInformation);
171+
146172
$this->digitalForm = $this->digitalFormsService->wrapDigitalForm($node);
147173
}
148174
else {

tests/phpunit/va_gov_form_builder/functional/Form/FormInfoTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace tests\phpunit\va_gov_form_builder\functional\Form;
44

5+
use Drupal\node\Entity\Node;
6+
use Drupal\paragraphs\Entity\Paragraph;
57
use tests\phpunit\va_gov_form_builder\Traits\SharedConstants;
68
use tests\phpunit\va_gov_form_builder\Traits\TestPageLoads;
79
use Tests\Support\Classes\VaGovExistingSiteBase;
@@ -137,6 +139,30 @@ public function testFormSubmissionSucceeds() {
137139
// Successful submission should take user to next page.
138140
$nextPageUrl = $this->getSession()->getCurrentUrl();
139141
$this->assertStringContainsString('/layout', $nextPageUrl);
142+
143+
// Form should have default "Your personal information" chapter.
144+
preg_match('|/form-builder\/(\d+)/layout|', $nextPageUrl, $matches);
145+
$createdNodeId = $matches[1];
146+
$createdNode = Node::load($createdNodeId);
147+
148+
$steps = $createdNode->get('field_chapters')->getValue();
149+
$this->assertNotEmpty($steps, 'Default chapter should be added on initial node creation.');
150+
151+
$paragraphId = $steps[0]['target_id'];
152+
$paragraph = Paragraph::load($paragraphId);
153+
$this->assertEquals($paragraph->bundle(), 'digital_form_your_personal_info');
154+
155+
// That chapter should have two sub-chapters:
156+
// 1. Name and date of birth.
157+
$nameAndDob = $paragraph->get('field_name_and_date_of_birth')->getValue();
158+
$nameAndDobParagraphId = $nameAndDob[0]['target_id'];
159+
$nameAndDobParagraph = Paragraph::load($nameAndDobParagraphId);
160+
$this->assertEquals($nameAndDobParagraph->bundle(), 'digital_form_name_and_date_of_bi');
161+
// 2. Identification information.
162+
$identificationInfo = $paragraph->get('field_identification_information')->getValue();
163+
$identificationInfoParagraphId = $identificationInfo[0]['target_id'];
164+
$identificationInfoParagraph = Paragraph::load($identificationInfoParagraphId);
165+
$this->assertEquals($identificationInfoParagraph->bundle(), 'digital_form_identification_info');
140166
}
141167

142168
/**

0 commit comments

Comments
 (0)