Closed (works as designed)
Project:
Drupal core
Version:
7.x-dev
Component:
field system
Priority:
Critical
Category:
Bug report
Assigned:
Issue tags:
Reporter:
Created:
8 Dec 2010 at 15:22 UTC
Updated:
15 Dec 2010 at 06:02 UTC
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
Comment #1
drcho commenteddo not use the solution shown above, it causes other problems.
Comment #2
drcho commentedassigned to field system component...
Comment #3
juves commentedsubscribe spam, sorry :D
Comment #4
yched commentedsubscribe for now
@plach, if you're around... :-)
Comment #5
greg606 commentedSubscribing as possibly fighting the same problem in #987478: Field language is not properly handled
Comment #6
bojanz commentedThree users so far in the Views queues reporting the same problem (field doesn't output anything when multiple languages are in use).
Comment #7
sylvain lecoy commentedPushing 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 ?
Comment #8
sylvain lecoy commentedstill happening in -dev.
Comment #9
carlos8f commentedsubscribing
Comment #10
dawehnerCan someone explain why views doesn't add the language field to id's query and ues this later for field_view_field?
Comment #11
plachI'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!
Comment #12
plachtagging :)
Comment #13
manos_ws commentedsubscribing
Comment #14
sylvain lecoy commentedFollowing 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 ?
Comment #15
plachThe 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).Comment #16
sylvain lecoy commentedThat makes sense, thank you.