Commit fd8fa3e4 authored by Dries's avatar Dries
Browse files

- Patch #1089174 by plach: rrepare view hooks do not receive the language parameter.

parent 79ebfd09
......@@ -348,7 +348,7 @@ function _field_invoke_multiple($op, $entity_type, $entities, &$a = NULL, &$b =
// fields with an empty array (those are not equivalent on update).
foreach ($grouped_entities[$field_id] as $id => $entity) {
foreach ($grouped_items[$field_id] as $langcode => $items) {
if ($grouped_items[$field_id][$langcode][$id] !== array() || isset($entity->{$field_name}[$langcode])) {
if (isset($grouped_items[$field_id][$langcode][$id]) && ($grouped_items[$field_id][$langcode][$id] !== array() || isset($entity->{$field_name}[$langcode]))) {
$entity->{$field_name}[$langcode] = $grouped_items[$field_id][$langcode][$id];
}
}
......
......@@ -2690,7 +2690,7 @@ class FieldTranslationsTestCase extends FieldTestCase {
$extra_languages = mt_rand(1, 4);
$languages = $available_languages = field_available_languages($this->entity_type, $this->field);
for ($i = 0; $i < $extra_languages; ++$i) {
$languages[] = $this->randomString(2);
$languages[] = $this->randomName(2);
}
// For each given language provide some random values.
......@@ -2715,10 +2715,14 @@ class FieldTranslationsTestCase extends FieldTestCase {
* Test the multilanguage logic of _field_invoke_multiple().
*/
function testFieldInvokeMultiple() {
// Enable field translations for the entity.
field_test_entity_info_translatable('test_entity', TRUE);
$values = array();
$options = array();
$entities = array();
$entity_type = 'test_entity';
$entity_count = mt_rand(1, 5);
$entity_count = mt_rand(2, 5);
$available_languages = field_available_languages($this->entity_type, $this->field);
for ($id = 1; $id <= $entity_count; ++$id) {
......@@ -2729,29 +2733,55 @@ class FieldTranslationsTestCase extends FieldTestCase {
// correctly uses the result of field_available_languages().
$extra_languages = mt_rand(1, 4);
for ($i = 0; $i < $extra_languages; ++$i) {
$languages[] = $this->randomString(2);
$languages[] = $this->randomName(2);
}
// For each given language provide some random values.
foreach ($languages as $langcode) {
for ($delta = 0; $delta < $this->field['cardinality']; $delta++) {
$values[$id][$langcode][$delta]['value'] = mt_rand(1, 127);
$language_count = count($languages);
for ($i = 0; $i < $language_count; ++$i) {
$langcode = $languages[$i];
// Avoid to populate at least one field translation to check that
// per-entity language suggestions work even when available field values
// are different for each language.
if ($i !== $id) {
for ($delta = 0; $delta < $this->field['cardinality']; $delta++) {
$values[$id][$langcode][$delta]['value'] = mt_rand(1, 127);
}
}
// Ensure that a language for which there is no field translation is
// used as display language to prepare per-entity language suggestions.
elseif (!isset($display_language)) {
$display_language = $langcode;
}
}
$entity->{$this->field_name} = $values[$id];
$entities[$id] = $entity;
// Store per-entity language suggestions.
$options['language'][$id] = field_language($entity_type, $entity, NULL, $display_language);
}
$grouped_results = _field_invoke_multiple('test_op_multiple', $entity_type, $entities);
foreach ($grouped_results as $id => $results) {
foreach ($results as $langcode => $result) {
$hash = hash('sha256', serialize(array($entity_type, $entities[$id], $this->field_name, $langcode, $values[$id][$langcode])));
// Check whether the parameters passed to _field_invoke() were correctly
// forwarded to the callback function.
$this->assertEqual($hash, $result, t('The result for entity %id/%language is correctly stored.', array('%id' => $id, '%language' => $langcode)));
if (isset($values[$id][$langcode])) {
$hash = hash('sha256', serialize(array($entity_type, $entities[$id], $this->field_name, $langcode, $values[$id][$langcode])));
// Check whether the parameters passed to _field_invoke() were correctly
// forwarded to the callback function.
$this->assertEqual($hash, $result, t('The result for entity %id/%language is correctly stored.', array('%id' => $id, '%language' => $langcode)));
}
}
$this->assertEqual(count($results), count($available_languages), t('No unavailable language has been processed for entity %id.', array('%id' => $id)));
}
$null = NULL;
$grouped_results = _field_invoke_multiple('test_op_multiple', $entity_type, $entities, $null, $null, $options);
foreach ($grouped_results as $id => $results) {
foreach ($results as $langcode => $result) {
$this->assertTrue(isset($options['language'][$id]), t('The result language %language for entity %id was correctly suggested (display language: %display_language).', array('%id' => $id, '%language' => $langcode, '%display_language' => $display_language)));
}
}
}
/**
......
......@@ -88,7 +88,9 @@ function field_test_field_test_op($entity_type, $entity, $field, $instance, $lan
function field_test_field_test_op_multiple($entity_type, $entities, $field, $instances, $langcode, &$items) {
$result = array();
foreach ($entities as $id => $entity) {
$result[$id] = array($langcode => hash('sha256', serialize(array($entity_type, $entity, $field['field_name'], $langcode, $items[$id]))));
if (isset($items[$id])) {
$result[$id] = array($langcode => hash('sha256', serialize(array($entity_type, $entity, $field['field_name'], $langcode, $items[$id]))));
}
}
return $result;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment