You are here

function currency_form_currency_exchanger_fixed_rates in Currency 7.2

Implements form build callback: CurrencyExchangerFixedRates' add/edit form.

1 string reference to 'currency_form_currency_exchanger_fixed_rates'
currency_menu in currency/currency.module
Implements hook_menu().

File

currency/currency.module, line 892
Provides currency information and allows users to add custom currencies.

Code

function currency_form_currency_exchanger_fixed_rates(array $form, array &$form_state, $currency_code_from = NULL, $currency_code_to = NULL) {
  $rate = $currency_code_from && $currency_code_to ? CurrencyExchangerFixedRates::load($currency_code_from, $currency_code_to) : NULL;
  $options = currency_options();
  $form['currency_code_from'] = array(
    '#default_value' => isset($options[$currency_code_from]) ? $currency_code_from : 'XXX',
    '#disabled' => !is_null($rate),
    '#options' => $options,
    '#required' => TRUE,
    '#title' => t('Source currency'),
    '#type' => 'select',
  );
  $form['currency_code_to'] = array(
    '#default_value' => isset($options[$currency_code_to]) ? $currency_code_to : 'XXX',
    '#disabled' => !is_null($rate),
    '#options' => $options,
    '#required' => TRUE,
    '#title' => t('Source currency'),
    '#type' => 'select',
  );
  $form['rate'] = array(
    '#currency_code' => 'XXX',
    '#default_value' => $rate,
    '#required' => TRUE,
    '#title' => t('Conversion rate'),
    '#type' => 'currency_amount',
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['save'] = array(
    '#name' => 'save',
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  if (!is_null($rate)) {
    $form['actions']['delete'] = array(
      '#limit_validation_errors' => array(
        array(
          'currency_code_from',
        ),
        array(
          'currency_code_to',
        ),
      ),
      '#name' => 'delete',
      '#type' => 'submit',
      '#value' => t('Delete'),
    );
  }
  $form['actions']['cancel'] = array(
    '#markup' => l(t('Cancel'), 'admin/config/regional/currency-exchange/fixed'),
    '#type' => 'markup',
  );
  return $form;
}