drupal_alter('field_attach_view', $result, $context) gets executed in function field_view_field() and in function field_attach_view().
Compared to function field_attach_view() the langcode is missing in $context in function field_view_field():
function field_attach_view($entity_type, EntityInterface $entity, $view_mode, $langcode = NULL) {
// Let other modules alter the renderable array.
$context = array(
'entity_type' => $entity_type,
'entity' => $entity,
'view_mode' => $view_mode,
'display' => $view_mode,
'langcode' => $langcode,
);
drupal_alter('field_attach_view', $output, $context);
}
function field_view_field($entity_type, $entity, $field_name, $display = array(), $langcode = NULL) {
// Invoke hook_field_attach_view_alter() to let other modules alter the
// renderable array, as in a full field_attach_view() execution.
$context = array(
'entity_type' => $entity_type,
'entity' => $entity,
'view_mode' => '_custom',
'display' => $display,
);
drupal_alter('field_attach_view', $result, $context);
}
This bug already exists in drupal 7 and breaks the indexing of nodes in apachesolr if the entity translation module is installed: #1820742: parameter $langcode of core function node_view() ignored
(The issues within Entity Translation have been fixed now, except this remaining bug in core.)
Attached you'll find a patch against drupal 8 where the bug still exists. After it gets committed a backport is required. But watch out, in drupal 7 the array key needs to be 'language' instead of 'langcode'.
Comment | File | Size | Author |
---|---|---|---|
#22 | field-field_view_attach_alter_langcode-1823306-22.patch | 2.03 KB | p-neyens |
#19 | 1823306_19_field_attach_view_alter_langcode.patch | 1.75 KB | p-neyens |
#16 | 1823306-missing_langcode.patch | 846 bytes | mkalkbrenner |
#12 | 1823306-12-field_attach_view_alter_langcode.patch | 2.68 KB | swentel |
#12 | interdiff.txt | 719 bytes | swentel |
Comments
Comment #1
plachI am afraid we need some tests here.
Comment #2
plachComment #3
mkalkbrennerhm, I'm not familar enough with drupal 8 testing right now to create a reasonable test for that.
On the other hand the bug is obvious:
According to the comment, function field_view_field() has do do the same as function field_attach_view(), but misses the langcode in context.
Comment #4
mkalkbrennerMeanwhile, here's the patch for d7.
Comment #5
webflo CreditAttribution: webflo commentedHow about that?
Comment #6
webflo CreditAttribution: webflo commentedComment #8
webflo CreditAttribution: webflo commentedMaybe
field_valid_language($context['langcode'], FALSE);
should be infield_view_field()
. I am not sure.Comment #10
nils.destoop CreditAttribution: nils.destoop commentedThis test should work.
Comment #11
nils.destoop CreditAttribution: nils.destoop commentedComment #12
swentel CreditAttribution: swentel commentedWhat's even worse is that field.api.php actually documents a langcode (previously language, renamed it in the patch) was passed :)
Reroll + RTBC
Comment #13
swentel CreditAttribution: swentel commentedCleaning tags
Comment #14
alexpottCommitted 9a53a21 and pushed to 8.x. Thanks!
Comment #15
David_Rothstein CreditAttribution: David_Rothstein commentedComment #16
mkalkbrennerre-test my patch from #4
Comment #17
swentel CreditAttribution: swentel commentedyes
Comment #18
David_Rothstein CreditAttribution: David_Rothstein commentedThe tests are missing from the D7 patch.
Comment #19
p-neyens CreditAttribution: p-neyens commentedTest for the backport to D7.
Comment #20
plachComment #22
p-neyens CreditAttribution: p-neyens commentedNew patch that includes previous patches from #16 and #19.
Comment #23
p-neyens CreditAttribution: p-neyens commentedComment #24
plachThanks!
Comment #27
David_Rothstein CreditAttribution: David_Rothstein commentedThat was a bogus test failure, so back to RTBC for now. (I didn't review the patch myself.)
Comment #30
dcam CreditAttribution: dcam commentedBack to RTBC.
Comment #33
David_Rothstein CreditAttribution: David_Rothstein commentedTestbot fluke.
Comment #34
David_Rothstein CreditAttribution: David_Rothstein commentedCommitted to 7.x - thanks!