You are here

function _languagefield_widget_value in Custom Language field 7

Callback function for widget.

1 string reference to '_languagefield_widget_value'
languagefield_field_widget_form_alter in ./languagefield.module
Adds a callback function to widget.

File

./languagefield.module, line 358
Provides a list of languages from ISO 639 standard. All variables of a $language-object can be found here: http://api.drupal.org/api/drupal/developer--globals.php/global/language

Code

function _languagefield_widget_value($element, $input = FALSE, $form_state) {
  if (!$input) {

    // First call the default value_callback function.
    $value_callback = 'form_type_' . $element['#type'] . '_value';
    if (function_exists($value_callback)) {
      $input = $value_callback($element, $input, $form_state);
    }
  }
  else {

    // We do the following, to ensure that the LANGUAGEFIELD_* default values
    // are converted before showing the widget.
    // (Widgets are not always processed when they are hidden.)
    $return = array();

    // The form is submitted.
    if (!is_array($input)) {
      $return = _languagefield_getLanguageConfigurationValues($input);
    }
    else {

      // Convert the values to real languagecodes,
      // but ONLY on Entity form, NOT in the 'field settings - default value'.
      // That is done via a filter in languagefield_field_widget_form_alter().
      foreach ($input as &$value) {
        $value = _languagefield_getLanguageConfigurationValues($value);
        $return[$value] = $value;
      }
    }
    return $return;
  }
  return $input;
}