/[drupal]/drupal/modules/locale/locale.field.inc
ViewVC logotype

Contents of /drupal/modules/locale/locale.field.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Mon Nov 2 05:57:05 2009 UTC (3 weeks, 5 days ago) by webchick
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-10, HEAD
Changes since 1.2: +2 -2 lines
File MIME type: text/x-php
#608424 by peximo and plach: Fixed notice when multilingual body display set to hidden (with tests).
1 <?php
2 // $Id: locale.field.inc,v 1.2 2009/10/31 16:06:36 dries Exp $
3
4 /**
5 * @file
6 * Field API multilingual handling.
7 */
8
9 /**
10 * Form submit handler for node_form().
11 *
12 * Update the field language according to the node language, changing the
13 * previous language if necessary.
14 */
15 function locale_field_node_form_update_field_language($form, &$form_state, $reset_previous = TRUE) {
16 $node = (object) $form_state['values'];
17 $available_languages = field_multilingual_content_languages();
18 // @todo: Unify language neutral language codes.
19 $selected_language = empty($node->language) ? FIELD_LANGUAGE_NONE : $node->language;
20 list(, , $bundle) = entity_extract_ids('node', $node);
21
22 foreach (field_info_instances('node', $bundle) as $instance) {
23 $field_name = $instance['field_name'];
24 $field = field_info_field($field_name);
25 $previous_language = $form[$field_name]['#language'];
26
27 // Handle a possible language change: previous language values are deleted,
28 // new ones are inserted.
29 if ($field['translatable'] && $previous_language != $selected_language) {
30 $form_state['values'][$field_name][$selected_language] = $node->{$field_name}[$previous_language];
31 if ($reset_previous) {
32 $form_state['values'][$field_name][$previous_language] = array();
33 }
34 }
35 }
36 }
37
38 /**
39 * Apply fallback rules to the given object.
40 *
41 * Parameters are the same of hook_field_attach_view().
42 */
43 function locale_field_fallback_view(&$output, $context) {
44 // Lazily init fallback values and candidates to avoid unnecessary calls.
45 $fallback_values = array();
46 $fallback_candidates = NULL;
47 list(, , $bundle) = entity_extract_ids($context['obj_type'], $context['object']);
48
49 foreach (field_info_instances($context['obj_type'], $bundle) as $instance) {
50 $field_name = $instance['field_name'];
51 $field = field_info_field($field_name);
52
53 // If the items array is empty then we have a missing field translation.
54 // @todo: Verify this assumption.
55 if (isset($output[$field_name]) && empty($output[$field_name]['items'])) {
56 if (!isset($fallback_candidates)) {
57 require_once DRUPAL_ROOT . '/includes/language.inc';
58 $fallback_candidates = language_fallback_get_candidates();
59 }
60
61 foreach ($fallback_candidates as $langcode) {
62 // Again if we have a non-empty array we assume the field translation is
63 // valid.
64 if (!empty($context['object']->{$field_name}[$langcode])) {
65 // Cache fallback values per language as fields might have different
66 // fallback values.
67 if (!isset($fallback_values[$langcode])) {
68 $fallback_values[$langcode] = field_attach_view($context['obj_type'], $context['object'], $context['build_mode'], $langcode);
69 }
70 // We are done, skip to the next field.
71 $output[$field_name] = $fallback_values[$langcode][$field_name];
72 break;
73 }
74 }
75 }
76 }
77 }

  ViewVC Help
Powered by ViewVC 1.1.2