public function PostalCodeSettingsForm::buildForm in Postal Code 8
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 ConfigFormBase::buildForm
File
- src/
Form/ PostalCodeSettingsForm.php, line 81
Class
- PostalCodeSettingsForm
- Postal code admin settings form.
Namespace
Drupal\postal_code\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$country_list = $this->countryManager
->getStandardList();
$postal_code_validation_data = $this->postalCodeValidation
->getValidationPatterns();
$options = array();
foreach ($postal_code_validation_data as $country_code => $info) {
$options[$country_code] = $country_list[mb_strtoupper($country_code)];
}
$form['postal_code_valid_countries'] = array(
'#type' => 'select',
'#title' => t('Valid "Any" Countries'),
'#size' => 16,
'#multiple' => TRUE,
'#options' => $options,
'#default_value' => $this->postalCodeSettings
->get('valid_countries'),
'#description' => '<p>' . t('Select the countr(y/ies) for Postal Code Validation for "Any" field type.') . '</p><p><em>' . t('This is most useful when you have a form that allows, for example, US and Canadian addresses.') . '</em></p><p><strong>' . t('VALIDATION ONLY OCCURS IF THE "VALIDATE" CHECKBOX BELOW IS SELECTED.') . '</strong></p>',
);
$form['postal_code_validate'] = array(
'#type' => 'checkbox',
'#title' => t('Validate'),
'#default_value' => $this->postalCodeSettings
->get('validate'),
'#description' => t('Validate submitted postal codes?'),
);
return parent::buildForm($form, $form_state);
}