public function CurrencyForm::validateCurrencyCode in Commerce Core 8.2
Validates the currency code.
File
- modules/
price/ src/ Form/ CurrencyForm.php, line 102
Class
Namespace
Drupal\commerce_price\FormCode
public function validateCurrencyCode(array $element, FormStateInterface $form_state, array $form) {
$currency = $this
->getEntity();
$currency_code = $element['#value'];
if (!preg_match('/^[A-Z]{3}$/', $currency_code)) {
$form_state
->setError($element, $this
->t('The currency code must consist of three uppercase letters.'));
}
elseif ($currency
->isNew()) {
$loaded_currency = $this->storage
->load($currency_code);
if ($loaded_currency) {
$form_state
->setError($element, $this
->t('The currency code is already in use.'));
}
}
}