You are here

function i18n_taxonomy_field_attach_view_alter in Internationalization 7

Implements hook_field_attach_view_alter().

File

i18n_taxonomy/i18n_taxonomy.module, line 264
i18n taxonomy module

Code

function i18n_taxonomy_field_attach_view_alter(&$output, $context) {

  // Copied from rdf_field_attach_view_alter of modules/rdf/rdf.module since we have another #formatter
  // Append term mappings on displayed taxonomy links.
  foreach (element_children($output) as $field_name) {
    $element =& $output[$field_name];
    if (isset($element['#field_type']) && $element['#field_type'] == 'taxonomy_term_reference' && $element['#formatter'] == 'i18n_taxonomy_term_reference_link') {
      foreach ($element['#items'] as $delta => $item) {

        // This function is invoked during entity preview when taxonomy term
        // reference items might contain free-tagging terms that do not exist
        // yet and thus have no $item['taxonomy_term'].
        if (isset($item['taxonomy_term'])) {
          $term = $item['taxonomy_term'];
          if (!empty($term->rdf_mapping['rdftype'])) {
            $element[$delta]['#options']['attributes']['typeof'] = $term->rdf_mapping['rdftype'];
          }
          if (!empty($term->rdf_mapping['name']['predicates'])) {
            $element[$delta]['#options']['attributes']['property'] = $term->rdf_mapping['name']['predicates'];
          }
        }
      }
    }
  }

  // Add language field for display
  if ($context['entity_type'] == 'taxonomy_term' && i18n_taxonomy_vocabulary_mode($context['entity']->vid, I18N_MODE_TRANSLATE)) {
    $output['language'] = array(
      '#type' => 'item',
      '#title' => t('Language'),
      '#markup' => i18n_language_name($context['entity']->language),
    );
  }
}