You are here

public function CountryForm::buildForm in Ubercart 8.4

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 EntityForm::buildForm

File

uc_country/src/Form/CountryForm.php, line 16

Class

CountryForm
Form controller for country forms.

Namespace

Drupal\uc_country\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);
  $country = $this->entity;
  $form['#title'] = $this
    ->t('Edit %country', [
    '%country' => $country
      ->label(),
  ]);
  $form['name'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Name'),
    '#default_value' => $country
      ->getName(),
  ];
  $form['address_format'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Address format'),
    '#default_value' => implode("\r\n", $country
      ->getAddressFormat()),
    '#rows' => 7,
  ];
  $form['help'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Address format variables'),
    '#collapsed' => TRUE,
  ];
  $form['help']['text'] = [
    '#theme' => 'table',
    '#header' => [
      $this
        ->t('Variable'),
      $this
        ->t('Description'),
    ],
    '#rows' => [
      [
        '!first_name',
        $this
          ->t("Customer's first name"),
      ],
      [
        '!last_name',
        $this
          ->t("Customer's last name"),
      ],
      [
        '!company',
        $this
          ->t('Company name'),
      ],
      [
        '!street1',
        $this
          ->t('First street address field'),
      ],
      [
        '!street2',
        $this
          ->t('Second street address field'),
      ],
      [
        '!city',
        $this
          ->t('City name'),
      ],
      [
        '!zone_name',
        $this
          ->t('Full name of the zone'),
      ],
      [
        '!zone_code',
        $this
          ->t('Abbreviation of the zone'),
      ],
      [
        '!postal_code',
        $this
          ->t('Postal code'),
      ],
      [
        '!country_name',
        $this
          ->t('Name of the country'),
      ],
      [
        '!country_code2',
        $this
          ->t('2 digit country abbreviation'),
      ],
      [
        '!country_code3',
        $this
          ->t('3 digit country abbreviation'),
      ],
    ],
    '#prefix' => '<p>' . $this
      ->t('The following variables should be used in configuring addresses for the countries you ship to:') . '</p>',
    '#suffix' => '<p>' . $this
      ->t('Adding _if to any country variable will make it display only for addresses whose country is different than the default store country.') . '</p>',
  ];
  return $form;
}