summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngie Byron2009-10-16 02:04:44 (GMT)
committerAngie Byron2009-10-16 02:04:44 (GMT)
commit6061fa9781205b4de2a5cc69a565036e5fb2bf97 (patch)
treefddd45aac58609796d174121e922a7acdaa9106c
parent5faaa376aa8c0bb5b1a17bca8f506f8431f795b0 (diff)
#565480 by plach and peximo: TF #2: Multilingual field handling. Integration between field API and locale module + translatable node bodies.
-rw-r--r--includes/bootstrap.inc15
-rw-r--r--includes/language.inc33
-rw-r--r--includes/locale.inc6
-rw-r--r--modules/field/field.info.inc2
-rw-r--r--modules/field/field.multilingual.inc37
-rw-r--r--modules/field/field.test5
-rw-r--r--modules/locale/locale.api.php7
-rw-r--r--modules/locale/locale.field.inc77
-rw-r--r--modules/locale/locale.info1
-rw-r--r--modules/locale/locale.module58
-rw-r--r--modules/locale/locale.test71
-rw-r--r--modules/node/node.module1
-rw-r--r--modules/path/path.test6
-rw-r--r--modules/simpletest/drupal_web_test_case.php3
-rw-r--r--modules/simpletest/tests/field_test.install11
-rw-r--r--modules/simpletest/tests/field_test.module9
-rw-r--r--modules/translation/translation.test14
17 files changed, 327 insertions, 29 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index fe9a954..83ab8ba 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -1627,7 +1627,7 @@ function drupal_language_initialize() {
// Ensure the language is correctly returned, even without multilanguage support.
// Useful for eg. XML/HTML 'lang' attributes.
- if (variable_get('language_count', 1) == 1) {
+ if (!drupal_multilingual()) {
$default = language_default();
foreach ($types as $type) {
$GLOBALS[$type] = $default;
@@ -1657,6 +1657,17 @@ function drupal_language_types() {
}
/**
+ * Return true if there is more than one language enabled.
+ */
+function drupal_multilingual() {
+ static $multilingual;
+ if (!isset($multilingual)) {
+ $multilingual = variable_get('language_count', 1) > 1;
+ }
+ return $multilingual;
+}
+
+/**
* Return an array of the available language types.
*/
function language_types() {
@@ -1672,7 +1683,7 @@ function language_list($field = 'language') {
$languages = &drupal_static(__FUNCTION__);
// Init language list
if (!isset($languages)) {
- if (variable_get('language_count', 1) > 1 || module_exists('locale')) {
+ if (drupal_multilingual() || module_exists('locale')) {
$languages['language'] = db_query('SELECT * FROM {languages} ORDER BY weight ASC, name ASC')->fetchAllAssoc('language');
}
else {
diff --git a/includes/language.inc b/includes/language.inc
index f170cf9..2fff7f3 100644
--- a/includes/language.inc
+++ b/includes/language.inc
@@ -396,3 +396,36 @@ function language_url_split_prefix($path, $languages) {
return array(FALSE, $path);
}
+
+/**
+ * Return the possible fallback languages ordered by language weight.
+ *
+ * @param
+ * The language type.
+ *
+ * @return
+ * An array of language codes.
+ */
+function language_fallback_get_candidates($type = LANGUAGE_TYPE_CONTENT) {
+ $fallback_candidates = &drupal_static(__FUNCTION__);
+
+ if (!isset($fallback_candidates)) {
+ $fallback_candidates = array();
+
+ // Get languages ordered by weight.
+ // Use array keys to avoid duplicated entries.
+ foreach (language_list('weight') as $languages) {
+ foreach ($languages as $language) {
+ $fallback_candidates[$language->language] = NULL;
+ }
+ }
+
+ $fallback_candidates = array_keys($fallback_candidates);
+ $fallback_candidates[] = FIELD_LANGUAGE_NONE;
+
+ // Let other modules hook in and add/change candidates.
+ drupal_alter('language_get_fallback_candidates', $fallback_candidates);
+ }
+
+ return $fallback_candidates;
+}
diff --git a/includes/locale.inc b/includes/locale.inc
index 8768be7..b905477 100644
--- a/includes/locale.inc
+++ b/includes/locale.inc
@@ -161,6 +161,7 @@ function locale_languages_overview_form_submit($form, &$form_state) {
// Changing the language settings impacts the interface.
cache_clear_all('*', 'cache_page', TRUE);
+ module_invoke_all('multilingual_settings_changed');
$form_state['redirect'] = 'admin/config/regional/language';
return;
@@ -362,6 +363,8 @@ function locale_languages_predefined_form_submit($form, &$form_state) {
batch_set($batch);
}
+ module_invoke_all('multilingual_settings_changed');
+
$form_state['redirect'] = 'admin/config/regional/language';
return;
}
@@ -469,7 +472,8 @@ function locale_languages_delete_form_submit($form, &$form_state) {
->fields(array('language' => ''))
->condition('language', $form_state['values']['langcode'])
->execute();
- $variables = array('%locale' => $languages[$form_state['values']['langcode']]->name);
+ module_invoke_all('multilingual_settings_changed');
+ $variables = array('%locale' => $languages[$form_state['values']['langcode']]->name);
drupal_set_message(t('The language %locale has been removed.', $variables));
watchdog('locale', 'The language %locale has been removed.', $variables);
}
diff --git a/modules/field/field.info.inc b/modules/field/field.info.inc
index 5f929a8..4edf243 100644
--- a/modules/field/field.info.inc
+++ b/modules/field/field.info.inc
@@ -147,7 +147,7 @@ function _field_info_collate_types($reset = FALSE) {
// Provide defaults.
$entity_info += array(
'cacheable' => TRUE,
- 'translation_handlers' => array(),
+ 'translation' => array(),
'bundles' => array(),
);
$entity_info['object keys'] += array(
diff --git a/modules/field/field.multilingual.inc b/modules/field/field.multilingual.inc
index 9dafe23..a929439 100644
--- a/modules/field/field.multilingual.inc
+++ b/modules/field/field.multilingual.inc
@@ -7,6 +7,13 @@
*/
/**
+ * Implement hook_multilingual_settings_changed().
+ */
+function field_multilingual_settings_changed() {
+ cache_clear_all('field_info_types', 'cache_field');
+}
+
+/**
* Collect the available languages for the given entity type and field.
*
* If an entity has a translation handler and the given field is translatable,
@@ -31,12 +38,14 @@ function field_multilingual_available_languages($obj_type, $field, $suggested_la
$field_name = $field['field_name'];
if (!isset($field_languages[$field_name]) || !empty($suggested_languages)) {
- $obj_info = field_info_fieldable_types($obj_type);
- if (!empty($obj_info['translation_handlers']) && $field['translatable']) {
- $available_languages = field_multilingual_content_languages();
+ $translation_handlers = field_multilingual_check_translation_handlers($obj_type);
+
+ if ($translation_handlers && $field['translatable']) {
// The returned languages are a subset of the intersection of enabled ones
// and suggested ones.
+ $available_languages = field_multilingual_content_languages();
$languages = !empty($suggested_languages) ? $available_languages = array_intersect($available_languages, $suggested_languages) : $available_languages;
+
foreach (module_implements('field_languages') as $module) {
$function = $module . '_field_languages';
$function($obj_type, $field, $languages);
@@ -71,20 +80,36 @@ function field_multilingual_content_languages() {
return array_keys(language_list() + array(FIELD_LANGUAGE_NONE => NULL));
}
-
/**
* Check if a module is registered as a translation handler for a given entity.
*
+ * If no handler is passed, simply check if there is any translation handler
+ * enabled for the given entity type.
+ *
* @param $obj_type
* The type of the entity whose fields are to be translated.
* @param $handler
* The name of the handler to be checked.
+ *
* @return
* TRUE, if the handler is allowed to manage field translations.
*/
-function field_multilingual_check_translation_handler($obj_type, $handler) {
+function field_multilingual_check_translation_handlers($obj_type, $handler = NULL) {
$obj_info = field_info_fieldable_types($obj_type);
- return isset($obj_info['translation_handlers'][$handler]);
+
+ if (isset($handler)) {
+ return isset($obj_info['translation'][$handler]) && !empty($obj_info['translation'][$handler]);
+ }
+ elseif (isset($obj_info['translation'])) {
+ foreach ($obj_info['translation'] as $handler_info) {
+ // The translation handler must use a non-empty data structure.
+ if (!empty($handler_info)) {
+ return TRUE;
+ }
+ }
+ }
+
+ return FALSE;
}
/**
diff --git a/modules/field/field.test b/modules/field/field.test
index c425585..999c74f 100644
--- a/modules/field/field.test
+++ b/modules/field/field.test
@@ -2272,11 +2272,12 @@ class FieldTranslationsTestCase extends FieldTestCase {
*/
function testFieldAvailableLanguages() {
// Test 'translatable' fieldable info.
+ field_test_entity_info_translatable('test_entity', FALSE);
$field = $this->field;
$field['field_name'] .= '_untranslatable';
$langcode = language_default();
$suggested_languages = array($langcode->language);
- $available_languages = field_multilingual_available_languages($this->obj_type, $field);
+ $available_languages = field_multilingual_available_languages($this->obj_type, $field, $suggested_languages);
$this->assertTrue(count($available_languages) == 1 && $available_languages[0] === FIELD_LANGUAGE_NONE, t('Untranslatable entity: suggested language ignored.'));
// Enable field translations for the entity.
@@ -2411,7 +2412,7 @@ class FieldTranslationsTestCase extends FieldTestCase {
// Enable field translations for nodes.
field_test_entity_info_translatable('node', TRUE);
$obj_info = field_info_fieldable_types('node');
- $this->assertTrue(count($obj_info['translation_handlers']), t('Nodes are translatable.'));
+ $this->assertTrue(count($obj_info['translation']), t('Nodes are translatable.'));
// Prepare the field translations.
$eid = $evid = 1;
diff --git a/modules/locale/locale.api.php b/modules/locale/locale.api.php
index b1805e2..461f459 100644
--- a/modules/locale/locale.api.php
+++ b/modules/locale/locale.api.php
@@ -137,5 +137,12 @@ function hook_language_negotiation_info_alter(array &$language_providers) {
}
/**
+ * Allow modules to react to language settings changes.
+ */
+function hook_multilingual_settings_changed() {
+ cache_clear_all('field_info_types', 'cache_field');
+}
+
+/**
* @} End of "addtogroup hooks".
*/
diff --git a/modules/locale/locale.field.inc b/modules/locale/locale.field.inc
new file mode 100644
index 0000000..bfb102e
--- /dev/null
+++ b/modules/locale/locale.field.inc
@@ -0,0 +1,77 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Field API multilingual handling.
+ */
+
+/**
+ * Form submit handler for node_form().
+ *
+ * Update the field language according to the node language, changing the
+ * previous language if necessary.
+ */
+function locale_field_node_form_update_field_language($form, &$form_state, $reset_previous = TRUE) {
+ $node = (object) $form_state['values'];
+ $available_languages = field_multilingual_content_languages();
+ // @todo: Unify language neutral language codes.
+ $selected_language = empty($node->language) ? FIELD_LANGUAGE_NONE : $node->language;
+ list(, , $bundle) = field_extract_ids('node', $node);
+
+ foreach (field_info_instances('node', $bundle) as $instance) {
+ $field_name = $instance['field_name'];
+ $field = field_info_field($field_name);
+ $previous_language = $form[$field_name]['#language'];
+
+ // Handle a possible language change: previous language values are deleted,
+ // new ones are inserted.
+ if ($field['translatable'] && $previous_language != $selected_language) {
+ $form_state['values'][$field_name][$selected_language] = $node->{$field_name}[$previous_language];
+ if ($reset_previous) {
+ $form_state['values'][$field_name][$previous_language] = array();
+ }
+ }
+ }
+}
+
+/**
+ * Apply fallback rules to the given object.
+ *
+ * Parameters are the same of hook_field_attach_view().
+ */
+function locale_field_fallback_view(&$output, $context) {
+ // Lazily init fallback values and candidates to avoid unnecessary calls.
+ $fallback_values = array();
+ $fallback_candidates = NULL;
+ list(, , $bundle) = field_extract_ids($context['obj_type'], $context['object']);
+
+ foreach (field_info_instances($context['obj_type'], $bundle) as $instance) {
+ $field_name = $instance['field_name'];
+ $field = field_info_field($field_name);
+
+ // If the items array is empty then we have a missing field translation.
+ // @todo: Verify this assumption.
+ if (empty($output[$field_name]['items'])) {
+ if (!isset($fallback_candidates)) {
+ require_once DRUPAL_ROOT . '/includes/language.inc';
+ $fallback_candidates = language_fallback_get_candidates();
+ }
+
+ foreach ($fallback_candidates as $langcode) {
+ // Again if we have a non-empty array we assume the field translation is
+ // valid.
+ if (!empty($context['object']->{$field_name}[$langcode])) {
+ // Cache fallback values per language as fields might have different
+ // fallback values.
+ if (!isset($fallback_values[$langcode])) {
+ $fallback_values[$langcode] = field_attach_view($context['obj_type'], $context['object'], $context['build_mode'], $langcode);
+ }
+ // We are done, skip to the next field.
+ $output[$field_name] = $fallback_values[$langcode][$field_name];
+ break;
+ }
+ }
+ }
+ }
+}
diff --git a/modules/locale/locale.info b/modules/locale/locale.info
index 02b8652..642b693 100644
--- a/modules/locale/locale.info
+++ b/modules/locale/locale.info
@@ -6,4 +6,5 @@ version = VERSION
core = 7.x
files[] = locale.module
files[] = locale.install
+files[] = locale.field.inc
files[] = locale.test
diff --git a/modules/locale/locale.module b/modules/locale/locale.module
index a241981..0d90233 100644
--- a/modules/locale/locale.module
+++ b/modules/locale/locale.module
@@ -386,13 +386,23 @@ function locale_form_node_type_form_alter(&$form, &$form_state) {
}
/**
+ * Return whether the given content type has multilingual support.
+ *
+ * @return
+ * True if multilingual support is enabled.
+ */
+function locale_multilingual_node_type($type_name) {
+ return (bool) variable_get('language_content_type_' . $type_name, 0);
+}
+
+/**
* Implement hook_form_alter().
*
* Adds language fields to forms.
*/
function locale_form_alter(&$form, &$form_state, $form_id) {
// Only alter user forms if there is more than one language.
- if (variable_get('language_count', 1) > 1) {
+ if (drupal_multilingual()) {
// Display language selector when either creating a user on the admin
// interface or editing a user account.
if (($form_id == 'user_register_form' && user_access('administer users')) || ($form_id == 'user_profile_form' && $form['#user_category'] == 'account')) {
@@ -400,7 +410,7 @@ function locale_form_alter(&$form, &$form_state, $form_id) {
}
}
if (isset($form['#id']) && $form['#id'] == 'node-form') {
- if (isset($form['#node']->type) && variable_get('language_content_type_' . $form['#node']->type, 0)) {
+ if (isset($form['#node']->type) && locale_multilingual_node_type($form['#node']->type)) {
$form['language'] = array(
'#type' => 'select',
'#title' => t('Language'),
@@ -416,6 +426,20 @@ function locale_form_alter(&$form, &$form_state, $form_id) {
'#value' => $default->language
);
}
+ $form['#submit'][] = 'locale_field_node_form_submit';
+ }
+}
+
+/**
+ * Form submit handler for node_form().
+ *
+ * Check if Locale is registered as a translation handler and handle possible
+ * node language changes.
+ */
+function locale_field_node_form_submit($form, &$form_state) {
+ if (field_multilingual_check_translation_handlers('node', 'locale')) {
+ module_load_include('inc', 'locale', 'locale.field');
+ locale_field_node_form_update_field_language($form, $form_state);
}
}
@@ -440,6 +464,34 @@ function locale_theme() {
}
/**
+ * Implement hook_field_attach_view_alter().
+ */
+function locale_field_attach_view_alter(&$output, $context) {
+ // In locale_field_fallback_view() we might call field_attach_view(). The
+ // static variable avoids unnecessary recursion.
+ static $recursion;
+
+ // Do not apply fallback rules if disabled or if Locale is not registered as a
+ // translation handler.
+ if (!$recursion && variable_get('locale_field_fallback_view', TRUE) && field_multilingual_check_translation_handlers($context['obj_type'], 'locale')) {
+ $recursion = TRUE;
+ module_load_include('inc', 'locale', 'locale.field');
+ locale_field_fallback_view($output, $context);
+ $recursion = FALSE;
+ }
+}
+
+/**
+ * Implement hook_entity_info_alter().
+ */
+function locale_entity_info_alter(&$entity_info) {
+ $enabled = drupal_multilingual();
+ foreach ($entity_info as $type => $info) {
+ $entity_info[$type]['translation']['locale'] = $enabled;
+ }
+}
+
+/**
* Implement hook_language_types_info().
*/
function locale_language_types_info() {
@@ -829,7 +881,7 @@ function locale_block_info() {
* Displays a language switcher. Only show if we have at least two languages.
*/
function locale_block_view($type) {
- if (variable_get('language_count', 1) > 1) {
+ if (drupal_multilingual()) {
$path = drupal_is_front_page() ? '<front>' : $_GET['q'];
$links = language_negotiation_get_switch_links($type, $path);
diff --git a/modules/locale/locale.test b/modules/locale/locale.test
index 7932bad..57413ec 100644
--- a/modules/locale/locale.test
+++ b/modules/locale/locale.test
@@ -16,6 +16,7 @@
* - a functional test for configuring a different path alias per language;
* - a functional test for configuring a different path alias per language;
* - a functional test for multilingual support by content type and on nodes.
+ * - a functional test for multilingual fields.
*/
@@ -986,6 +987,7 @@ class LocaleUninstallFunctionalTest extends DrupalWebTestCase {
$this->assertEqual($language_count, 1, t('Language count: %count', array('%count' => $language_count)));
// Check language negotiation.
+ require_once DRUPAL_ROOT . '/includes/language.inc';
$this->assertTrue(count(language_types()) == count(drupal_language_types()), t('Language types reset'));
$language_negotiation = language_negotiation_get(LANGUAGE_TYPE_INTERFACE) == LANGUAGE_NEGOTIATION_DEFAULT;
$this->assertTrue($language_negotiation, t('Interface language negotiation: %setting', array('%setting' => t($language_negotiation ? 'none' : 'set'))));
@@ -1396,7 +1398,7 @@ class LocaleContentFunctionalTest extends DrupalWebTestCase {
$edit = array(
'type' => 'page',
'title' => array(FIELD_LANGUAGE_NONE => array(array('value' => $node_title))),
- 'body' => array(FIELD_LANGUAGE_NONE => array(array('value' => $node_body))),
+ 'body' => array($langcode => array(array('value' => $node_body))),
'language' => $langcode,
);
$node = $this->drupalCreateNode($edit);
@@ -1619,6 +1621,73 @@ class UILanguageNegotiationTest extends DrupalWebTestCase {
}
}
+class LocaleMultilingualFieldsFunctionalTest extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Multilingual fields',
+ 'description' => 'Test multilingual support for fields.',
+ 'group' => 'Locale',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('locale');
+ }
+
+ function testMultilingualNodeForm() {
+ // Setup users.
+ $admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages', 'create page content', 'edit own page content'));
+ $this->drupalLogin($admin_user);
+
+ // Add a new language.
+ require_once DRUPAL_ROOT . '/includes/locale.inc';
+ locale_add_language('it', 'Italian', 'Italiano', LANGUAGE_LTR, '', '', TRUE, FALSE);
+
+ // Set page content type to use multilingual support.
+ $this->drupalGet('admin/structure/types/manage/page');
+ $this->assertText(t('Multilingual support'), t('Multilingual support fieldset present on content type configuration form.'));
+ $edit = array(
+ 'language_content_type' => 1,
+ );
+ $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
+ $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Page')), t('Page content type has been updated.'));
+
+ // Create page content.
+ $langcode = FIELD_LANGUAGE_NONE;
+ $title_key = "title[$langcode][0][value]";
+ $title_value = $this->randomName(8);
+ $body_key = "body[$langcode][0][value]";
+ $body_value = $this->randomName(16);
+
+ // Create node to edit.
+ $edit = array();
+ $edit[$title_key] = $title_value;
+ $edit[$body_key] = $body_value;
+ $edit['language'] = 'en';
+ $this->drupalPost('node/add/page', $edit, t('Save'));
+
+ // Check that the node exists in the database.
+ $node = $this->drupalGetNodeByTitle($edit[$title_key]);
+ $this->assertTrue($node, t('Node found in database.'));
+
+ $assert = isset($node->body['en']) && !isset($node->body[FIELD_LANGUAGE_NONE]) && $node->body['en'][0]['value'] == $body_value;
+ $this->assertTrue($assert, t('Field language correctly set.'));
+
+ // Change node language.
+ $this->drupalGet("node/$node->nid/edit");
+ $edit = array(
+ $title_key => $this->randomName(8),
+ 'language' => 'it'
+ );
+ $this->drupalPost(NULL, $edit, t('Save'));
+ $node = $this->drupalGetNodeByTitle($edit[$title_key]);
+ $this->assertTrue($node, t('Node found in database.'));
+
+ $assert = isset($node->body['it']) && !isset($node->body['en']) && $node->body['it'][0]['value'] == $body_value;
+ $this->assertTrue($assert, t('Field language correctly changed.'));
+ }
+}
+
/**
* Functional tests for localizing date formats.
*/
diff --git a/modules/node/node.module b/modules/node/node.module
index db50ea9..0d7940a 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -534,6 +534,7 @@ function node_configure_fields($type) {
$field = array(
'field_name' => 'body',
'type' => 'text_with_summary',
+ 'translatable' => TRUE,
);
$field = field_create_field($field);
}
diff --git a/modules/path/path.test b/modules/path/path.test
index 84ce3b0..4410b46 100644
--- a/modules/path/path.test
+++ b/modules/path/path.test
@@ -181,7 +181,6 @@ class PathLanguageTestCase extends DrupalWebTestCase {
$edit['langcode'] = 'fr';
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
- drupal_static_reset('language_list');
// Set language negotiation to "Path prefix with fallback".
include_once DRUPAL_ROOT . '/includes/locale.inc';
@@ -215,9 +214,10 @@ class PathLanguageTestCase extends DrupalWebTestCase {
$this->drupalGet('node/' . $english_node->nid . '/translate');
$this->clickLink(t('add translation'));
$edit = array();
+ $langcode = 'fr';
+ $edit["body[$langcode][0][value]"] = $this->randomName();
$langcode = FIELD_LANGUAGE_NONE;
$edit["title[$langcode][0][value]"] = $this->randomName();
- $edit["body[$langcode][0][value]"] = $this->randomName();
$edit['path'] = $this->randomName();
$this->drupalPost(NULL, $edit, t('Save'));
@@ -234,9 +234,9 @@ class PathLanguageTestCase extends DrupalWebTestCase {
$this->assertText($french_node->title[FIELD_LANGUAGE_NONE][0]['value'], 'Alias for French translation works.');
// Confirm that the alias is returned by url().
+ drupal_static_reset('language_list');
$languages = language_list();
$url = url('node/' . $french_node->nid, array('language' => $languages[$french_node->language]));
$this->assertTrue(strpos($url, $edit['path']), t('URL contains the path alias.'));
}
}
-
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index b5cdee0..88850e4 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -730,7 +730,8 @@ class DrupalWebTestCase extends DrupalTestCase {
'value' => $this->randomName(32),
'format' => filter_default_format(),
);
- $settings['body'][FIELD_LANGUAGE_NONE][0] += $body;
+ $langcode = isset($settings['language']) ? $settings['language'] : FIELD_LANGUAGE_NONE;
+ $settings['body'][$langcode][0] += $body;
$node = (object) $settings;
node_save($node);
diff --git a/modules/simpletest/tests/field_test.install b/modules/simpletest/tests/field_test.install
index 83beb5e..2bb1701 100644
--- a/modules/simpletest/tests/field_test.install
+++ b/modules/simpletest/tests/field_test.install
@@ -7,6 +7,17 @@
*/
/**
+ * Implement hook_install().
+ */
+function field_test_install() {
+ // hook_entity_info_alter() needs to be executed as last.
+ db_update('system')
+ ->fields(array('weight' => 1))
+ ->condition('name', 'field_test')
+ ->execute();
+}
+
+/**
* Implement hook_schema().
*/
function field_test_schema() {
diff --git a/modules/simpletest/tests/field_test.module b/modules/simpletest/tests/field_test.module
index d5c35d0..8cc99b1 100644
--- a/modules/simpletest/tests/field_test.module
+++ b/modules/simpletest/tests/field_test.module
@@ -93,8 +93,13 @@ function field_test_entity_info() {
* Implement hook_entity_info_alter().
*/
function field_test_entity_info_alter(&$entity_info) {
+ // Enable/disable field_test as a translation handler.
foreach (field_test_entity_info_translatable() as $obj_type => $translatable) {
- $entity_info[$obj_type]['translation_handlers']['field_test'] = TRUE;
+ $entity_info[$obj_type]['translation']['field_test'] = $translatable;
+ }
+ // Disable locale as a translation handler.
+ foreach (field_info_fieldable_types() as $obj_type => $info) {
+ $entity_info[$obj_type]['translation']['locale'] = FALSE;
}
}
@@ -646,7 +651,7 @@ function field_test_field_languages($obj_type, $field, &$languages) {
*/
function field_test_entity_info_translatable($obj_type = NULL, $translatable = NULL) {
$stored_value = &drupal_static(__FUNCTION__, array());
- if (isset($obj_type) && isset($translatable)) {
+ if (isset($obj_type)) {
$stored_value[$obj_type] = $translatable;
_field_info_collate_types(TRUE);
}
diff --git a/modules/translation/translation.test b/modules/translation/translation.test
index aae647a..c56c148 100644
--- a/modules/translation/translation.test
+++ b/modules/translation/translation.test
@@ -68,7 +68,7 @@ class TranslationTestCase extends DrupalWebTestCase {
// Update original and mark translation as outdated.
$edit = array();
- $edit["body[$langcode][0][value]"] = $this->randomName();
+ $edit["body[$node->language][0][value]"] = $this->randomName();
$edit['translation[retranslate]'] = TRUE;
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->assertRaw(t('Page %title has been updated.', array('%title' => $node_title)), t('Original node updated.'));
@@ -79,7 +79,7 @@ class TranslationTestCase extends DrupalWebTestCase {
// Update translation and mark as updated.
$edit = array();
- $edit["body[$langcode][0][value]"] = $this->randomName();
+ $edit["body[$node_translation->language][0][value]"] = $this->randomName();
$edit['translation[status]'] = FALSE;
$this->drupalPost('node/' . $node_translation->nid . '/edit', $edit, t('Save'));
$this->assertRaw(t('Page %title has been updated.', array('%title' => $node_translation_title)), t('Translated node updated.'));
@@ -133,10 +133,10 @@ class TranslationTestCase extends DrupalWebTestCase {
$edit["body[$langcode][0][value]"] = $body;
$edit['language'] = $language;
$this->drupalPost('node/add/page', $edit, t('Save'));
- $this->assertRaw(t('Page %title has been created.', array('%title' => $edit["title[$langcode][0][value]"])), t('Page created.'));
+ $this->assertRaw(t('Page %title has been created.', array('%title' => $title)), t('Page created.'));
// Check to make sure the node was created.
- $node = $this->drupalGetNodeByTitle($edit["title[$langcode][0][value]"]);
+ $node = $this->drupalGetNodeByTitle($title);
$this->assertTrue($node, t('Node found in database.'));
return $node;
@@ -156,12 +156,12 @@ class TranslationTestCase extends DrupalWebTestCase {
$edit = array();
$langcode = FIELD_LANGUAGE_NONE;
$edit["title[$langcode][0][value]"] = $title;
- $edit["body[$langcode][0][value]"] = $body;
+ $edit["body[$language][0][value]"] = $body;
$this->drupalPost(NULL, $edit, t('Save'));
- $this->assertRaw(t('Page %title has been created.', array('%title' => $edit["title[$langcode][0][value]"])), t('Translation created.'));
+ $this->assertRaw(t('Page %title has been created.', array('%title' => $title)), t('Translation created.'));
// Check to make sure that translation was successful.
- $node = $this->drupalGetNodeByTitle($edit["title[$langcode][0][value]"]);
+ $node = $this->drupalGetNodeByTitle($title);
$this->assertTrue($node, t('Node found in database.'));
return $node;