I tried to find a bug in the field output of the D7 views module ( http://drupal.org/node/986064 ) but found out that it comes from the field module function field_view_field (field.module).

In my german drupal7-rc1 the field_view_field function receives the right language only for the first field.

It's the line

field_language($entity_type, $entity, $field_name, $langcode);

which returns "und" (LANGUAGE_NONE in bootstrap.inc)

After that field_view_field sets $options['language'] to 'und'
and now the called function _field_invoke_default returns no value.

I don't know the concept of translation handling in Drupal7, but it works for me with changing the function field_language from:

D7-rc1

function field_language($entity_type, $entity, $field_name = NULL, $langcode = NULL) {
  $display_languages = &drupal_static(__FUNCTION__, array());
  list($id, , $bundle) = entity_extract_ids($entity_type, $entity);
  $langcode = field_valid_language($langcode, FALSE);

  if (!isset($display_languages[$entity_type][$id][$langcode])) {
    $display_language = array();

    // By default display language is set to LANGUAGE_NONE if the field
    // translation is not available. It is up to translation handlers to
    // implement language fallback rules.
    foreach (field_info_instances($entity_type, $bundle) as $instance) {
      $display_language[$instance['field_name']] = isset($entity->{$instance['field_name']}[$langcode]) ? $langcode : LANGUAGE_NONE;
    }

    if (field_has_translation_handler($entity_type)) {
      $context = array(
        'entity_type' => $entity_type,
        'entity' => $entity,
        'language' => $langcode,
      );
      drupal_alter('field_language', $display_language, $context);
    }

    $display_languages[$entity_type][$id][$langcode] = $display_language;
  }

  $display_language = $display_languages[$entity_type][$id][$langcode];

  // Single-field mode.
  if (isset($field_name)) {
    return isset($display_language[$field_name]) ? $display_language[$field_name] : FALSE;
  }

  return $display_language;
}

to

function field_language($entity_type, $entity, $field_name = NULL, $langcode = NULL) {
  $display_languages = &drupal_static(__FUNCTION__, array());
  list($id, , $bundle) = entity_extract_ids($entity_type, $entity);
  $langcode = field_valid_language($langcode, FALSE);
  
  if (!isset($display_languages[$entity_type][$id][$field_name][$langcode])) {
  	$display_language = array();

    $display_language[$field_name] = isset($entity->$field_name[$langcode]) ? $langcode : LANGUAGE_NONE;

    if (field_has_translation_handler($entity_type)) {
      $context = array(
        'entity_type' => $entity_type,
        'entity' => $entity,
        'language' => $langcode,
      );
      drupal_alter('field_language', $display_language, $context);
    }

    $display_languages[$entity_type][$id][$langcode] = $display_language;
  }

  $display_language = $display_languages[$entity_type][$id][$langcode];

  // Single-field mode.
  if (isset($field_name)) {
    return isset($display_language[$field_name]) ? $display_language[$field_name] : FALSE;
  }

  return $display_language;
}

Comments

drcho’s picture

do not use the solution shown above, it causes other problems.

drcho’s picture

Component: other » field system

assigned to field system component...

juves’s picture

subscribe spam, sorry :D

yched’s picture

subscribe for now

@plach, if you're around... :-)

greg606’s picture

Subscribing as possibly fighting the same problem in #987478: Field language is not properly handled

bojanz’s picture

Three users so far in the Views queues reporting the same problem (field doesn't output anything when multiple languages are in use).

sylvain lecoy’s picture

Priority: Major » Critical

Pushing this as critical since the system is not usable with this bug on multilingual site.

The only question is, because the language is not defined: views doesn't handle correctly the language field, or field system should assign the default language to a field ?

sylvain lecoy’s picture

Version: 7.0-rc1 » 7.x-dev

still happening in -dev.

carlos8f’s picture

subscribing

dawehner’s picture

Can someone explain why views doesn't add the language field to id's query and ues this later for field_view_field?

plach’s picture

Assigned: Unassigned » plach

I'll try to understand what is happening ASAP.

@yched:

I have a look to the translatable fields queue every day, if you find a field issue that you think I should see, would you mind to tag it? Thanks!

plach’s picture

Issue tags: +translatable fields

tagging :)

manos_ws’s picture

subscribing

sylvain lecoy’s picture

Can someone explain why views doesn't add the language field to id's query and ues this later for field_view_field?

Following the rapid hack given here: http://drupal.org/node/987478. I think we have two approaches to fixe this bug.

1 - Puting a default value for language in the field system
2 - Making views handle this lack of value by replacing it with the default language.

What do you guys think ?

plach’s picture

Status: Active » Closed (works as designed)

The problem is in views_handler_field_field.inc, line 240: field_view_field() expects to have a full entity as parameter (or at least a data structure holding all the fields to be displayed, e.g. a row). The current code causes the static caches to be incomplete and so no language is found for every field besides the first (for every different language).

sylvain lecoy’s picture

That makes sense, thank you.