You are here

function _languagefield_theme_option in Custom Language field 7

Helper function to theme an option in widget and formatter. @TODO: turn into a real theme-function. Elements are now shown in fixed order.

Parameters

$settings: taken from field-, widget- or formatter-settings.:

2 calls to _languagefield_theme_option()
languagefield_field_formatter_view in ./languagefield.module
Implements hook_field_formatter_view().
languagefield_options_list in ./languagefield.module
Implements hook_options_list(). Returns 'all' or 'enabled' languages, according to field settings.

File

./languagefield.module, line 295
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_theme_option($item, &$settings) {
  $markup = array();

  // Add a language icon. We might better use languageicons_link_add().
  // @TODO: doesn't work for the Widget, even though hook_options_list says the <img>-tab is allowed.
  if (!empty($settings['format']['icon']) && module_exists('languageicons')) {
    $language['language'] = $item['value'];
    $variables = array(
      'language' => (object) $language,
      // TODO: what happens when no icon for this language code
      'title' => !empty($item['name']) ? $item['name'] : '',
    );
    $markup[] = theme('languageicons_icon', $variables);
  }
  if (!empty($settings['format']['iso']) && !empty($item['value'])) {
    $markup[] = $item['value'];
  }
  if (!empty($settings['format']['name']) && !empty($item['name'])) {
    $markup[] = $item['name'];
  }
  if (!empty($settings['format']['name_native']) && !empty($item['name_native'])) {
    $markup[] = $item['name_native'];
  }
  $markup = empty($markup) && isset($item['name']) ? $item['name'] : implode(' ', $markup);
  return $markup;
}