You are here

public function PostalCodeItem::fieldSettingsForm in Postal Code 8

Returns a form for the field-level settings.

Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure field-level settings.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.

Return value

array The form definition for the field settings.

Overrides FieldItemBase::fieldSettingsForm

File

src/Plugin/Field/FieldType/PostalCodeItem.php, line 70

Class

PostalCodeItem
Plugin implementation of the 'postal_code' field type.

Namespace

Drupal\postal_code\Plugin\Field\FieldType

Code

public function fieldSettingsForm(array $form, FormStateInterface $form_state) {

  // Get base form from FileItem.
  $element = parent::fieldSettingsForm($form, $form_state);
  $settings = $this
    ->getSettings();
  $options = array(
    'any' => (string) $this
      ->t('Any'),
  );
  $postal_code_validation_data = $this->postalCodeValidation
    ->getValidationPatterns();
  $countrylist = CountryManager::getStandardList();
  foreach ($postal_code_validation_data as $country => $regex) {
    $options[$country] = $countrylist[mb_strtoupper($country)]
      ->render();
  }
  $value = isset($settings['country_select']) ? $settings['country_select'] : 'any';
  $element['country_select'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Country'),
    '#options' => $options,
    '#default_value' => $value,
    '#description' => $this
      ->t('Select country for validation'),
  );
  return $element;
}