You are here

function currency_form_currency_sign_process in Currency 7.2

Implements form process callback for a currency_sign element.

1 string reference to 'currency_form_currency_sign_process'
currency_element_info in currency/currency.module
Implements hook_element_info().

File

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

Code

function currency_form_currency_sign_process(array $element, array &$form_state, array &$form) {
  $currency = FALSE;
  $currency = new Currency();
  if ($element['#currency_code']) {
    try {
      $currency
        ->resourceLoad($element['#currency_code']);
    } catch (Exception $e) {
    }
  }
  if (!$currency) {
    $currency
      ->resourceLoad('XXX');
  }

  // Modify the element.
  $element['#tree'] = TRUE;
  $element['#theme_wrappers'][] = 'form_element';
  $element['#attached']['css'] = array(
    drupal_get_path('module', 'currency') . '/currency.css',
  );
  $signs = array_merge(array(
    $currency->sign,
  ), $currency->alternativeSigns);
  $signs = array_combine($signs, $signs);
  $signs = array_unique(array_filter(array_merge(array(
    CURRENCY_SIGN_FORM_ELEMENT_CUSTOM_VALUE => t('- Custom -'),
  ), $signs)));
  asort($signs);
  $element['sign'] = array(
    '#default_value' => in_array($element['#default_value'], $signs) ? $element['#default_value'] : CURRENCY_SIGN_FORM_ELEMENT_CUSTOM_VALUE,
    '#empty_value' => '',
    '#options' => $signs,
    '#required' => $element['#required'],
    '#title' => t('Sign'),
    '#title_display' => 'invisible',
    '#type' => 'select',
  );
  $sign_js_selector = '.form-type-currency-sign .form-select';
  $element['sign_custom'] = array(
    '#attached' => array(
      'css' => array(
        drupal_get_path('module', 'currency') . '/currency.css',
      ),
    ),
    '#default_value' => $element['#default_value'],
    '#states' => array(
      'visible' => array(
        $sign_js_selector => array(
          'value' => CURRENCY_SIGN_FORM_ELEMENT_CUSTOM_VALUE,
        ),
      ),
    ),
    '#title' => t('Custom sign'),
    '#title_display' => 'invisible',
    '#type' => 'textfield',
  );
  return $element;
}