You are here

public function CurrencyForm::form in Currency 8.3

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Entity/Currency/CurrencyForm.php, line 88

Class

CurrencyForm
Provides a currency add/edit form.

Namespace

Drupal\currency\Entity\Currency

Code

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

  /** @var \Drupal\currency\Entity\CurrencyInterface $currency */
  $currency = $this
    ->getEntity();
  $form['currency_code'] = array(
    '#default_value' => $currency
      ->getCurrencyCode(),
    '#disabled' => !$currency
      ->isNew(),
    '#element_validate' => array(
      array(
        $this,
        'validateCurrencyCode',
      ),
    ),
    '#maxlength' => 3,
    '#pattern' => '[a-zA-Z]{3}',
    '#placeholder' => 'XXX',
    '#required' => TRUE,
    '#size' => 3,
    '#title' => $this
      ->t('ISO 4217 code'),
    '#type' => 'textfield',
  );
  $form['currency_number'] = array(
    '#default_value' => $currency
      ->getCurrencyNumber(),
    '#element_validate' => array(
      array(
        $this,
        'validateCurrencyNumber',
      ),
    ),
    '#maxlength' => 3,
    '#pattern' => '[\\d]{3}',
    '#placeholder' => '999',
    '#size' => 3,
    '#title' => $this
      ->t('ISO 4217 number'),
    '#type' => 'textfield',
  );
  $form['status'] = array(
    '#default_value' => $currency
      ->status(),
    '#title' => $this
      ->t('Enabled'),
    '#type' => 'checkbox',
  );
  $form['label'] = array(
    '#default_value' => $currency
      ->label(),
    '#maxlength' => 255,
    '#required' => TRUE,
    '#title' => $this
      ->t('Name'),
    '#type' => 'textfield',
  );
  $form['sign'] = array(
    '#currency_code' => $currency
      ->getCurrencyCode(),
    '#default_value' => $currency
      ->getSign(),
    '#title' => $this
      ->t('Sign'),
    '#type' => 'currency_sign',
  );
  $form['subunits'] = array(
    '#default_value' => $currency
      ->getSubunits(),
    '#min' => 0,
    '#required' => TRUE,
    '#title' => $this
      ->t('Number of subunits'),
    '#type' => 'number',
  );
  $form['rounding_step'] = array(
    '#default_value' => $currency
      ->getRoundingStep(),
    '#element_validate' => array(
      array(
        $this,
        'validateRoundingStep',
      ),
    ),
    '#required' => TRUE,
    '#title' => $this
      ->t('Rounding step'),
    '#type' => 'textfield',
  );
  return parent::form($form, $form_state, $currency);
}