public function CustomerProfileTestForm::buildForm in Commerce Core 8.2
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- modules/
order/ tests/ modules/ commerce_order_test/ src/ Form/ CustomerProfileTestForm.php, line 75
Class
- CustomerProfileTestForm
- A form for testing the customer_profile inline form.
Namespace
Drupal\commerce_order_test\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $profile = NULL, $admin = NULL) {
if (!$profile) {
$profile_storage = $this->entityTypeManager
->getStorage('profile');
/** @var \Drupal\profile\Entity\ProfileInterface $profile */
$profile = $profile_storage
->create([
'type' => 'customer',
'uid' => 0,
]);
}
$inline_form = $this->inlineFormManager
->createInstance('customer_profile', [
'profile_scope' => 'billing',
'available_countries' => [
'FR',
'RS',
'US',
'HU',
],
'address_book_uid' => $this->currentUser
->id(),
// Turn on copy_on_save for admins to exercise that code path as well.
'copy_on_save' => $admin,
'admin' => $admin,
], $profile);
$form['profile'] = [
'#parents' => [
'profile',
],
'#inline_form' => $inline_form,
];
$form['profile'] = $inline_form
->buildInlineForm($form['profile'], $form_state);
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
];
return $form;
}