Commit 34a8a369 authored by webchick's avatar webchick

#367595 by plach, catch, sun, yched, et al: Added support for translatable fields to Field API.

parent bc23bfaa
......@@ -248,11 +248,12 @@ EOF;
}
function createSampleNodes() {
$langcode = FIELD_LANGUAGE_NONE;
// Post 5 articles.
for ($i = 0; $i < 5; $i++) {
$edit = array();
$edit['title'] = $this->randomName();
$edit['body[0][value]'] = $this->randomName();
$edit["body[$langcode][0][value]"] = $this->randomName();
$this->drupalPost('node/add/article', $edit, t('Save'));
}
}
......
......@@ -152,7 +152,8 @@ class BlogTestCase extends DrupalWebTestCase {
// Edit blog node.
$edit = array();
$edit['title'] = 'node/' . $node->nid;
$edit['body[0][value]'] = $this->randomName(256);
$langcode = FIELD_LANGUAGE_NONE;
$edit["body[$langcode][0][value]"] = $this->randomName(256);
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->assertRaw(t('Blog entry %title has been updated.', array('%title' => $edit['title'])), t('Blog node was edited'));
......
......@@ -213,7 +213,7 @@ function blogapi_blogger_new_post($appkey, $blogid, $username, $password, $conte
}
else {
$edit['title'] = blogapi_blogger_title($content);
$edit['body'][0]['value'] = $content;
$edit['body'][FIELD_LANGUAGE_NONE][0]['value'] = $content;
}
if (!node_access('create', $edit['type'])) {
......@@ -274,12 +274,12 @@ function blogapi_blogger_edit_post($appkey, $postid, $username, $password, $cont
// Check for bloggerAPI vs. metaWeblogAPI.
if (is_array($content)) {
$node->title = $content['title'];
$node->body[0]['value'] = $content['description'];
$node->body[FIELD_LANGUAGE_NONE][0]['value'] = $content['description'];
_blogapi_mt_extra($node, $content);
}
else {
$node->title = blogapi_blogger_title($content);
$node->body[0]['value'] = $content;
$node->body[FIELD_LANGUAGE_NONE][0]['value'] = $content;
}
module_invoke_all('node_blogapi_edit', $node);
......@@ -895,14 +895,14 @@ function _blogapi_mt_extra($node, $struct) {
// Merge the 3 body sections (description, mt_excerpt, mt_text_more) into one body.
if ($struct['mt_excerpt']) {
$node->body[0]['value'] = $struct['mt_excerpt'] . '<!--break-->' . $node->body[0]['value'];
$node->body[FIELD_LANGUAGE_NONE][0]['value'] = $struct['mt_excerpt'] . '<!--break-->' . $node->body[FIELD_LANGUAGE_NONE][0]['value'];
}
if ($struct['mt_text_more']) {
$node->body[0]['value'] = $node->body[0]['value'] . '<!--extended-->' . $struct['mt_text_more'];
$node->body[FIELD_LANGUAGE_NONE][0]['value'] = $node->body[FIELD_LANGUAGE_NONE][0]['value'] . '<!--extended-->' . $struct['mt_text_more'];
}
if ($struct['mt_convert_breaks']) {
$node->body[0]['format'] = $struct['mt_convert_breaks'];
$node->body[FIELD_LANGUAGE_NONE][0]['format'] = $struct['mt_convert_breaks'];
}
if ($struct['dateCreated']) {
......@@ -925,8 +925,8 @@ function _blogapi_get_post($node, $bodies = TRUE) {
);
if ($bodies) {
$body = $node->body[0]['value'];
$format = $node->body[0]['format'];
$body = $node->body[FIELD_LANGUAGE_NONE][0]['value'];
$format = $node->body[FIELD_LANGUAGE_NONE][0]['format'];
if ($node->comment == 1) {
$comment = 2;
}
......
......@@ -141,7 +141,7 @@ class BookTestCase extends DrupalWebTestCase {
// Check printer friendly version.
$this->drupalGet('book/export/html/' . $node->nid);
$this->assertText($node->title, t('Printer friendly title found.'));
$this->assertRaw(check_markup($node->body[0]['value'], $node->body[0]['format']), t('Printer friendly body found.'));
$this->assertRaw(check_markup($node->body[FIELD_LANGUAGE_NONE][0]['value'], $node->body[FIELD_LANGUAGE_NONE][0]['format']), t('Printer friendly body found.'));
$number++;
}
......@@ -173,7 +173,8 @@ class BookTestCase extends DrupalWebTestCase {
$edit = array();
$edit['title'] = $number . ' - SimpleTest test node ' . $this->randomName(10);
$edit['body[0][value]'] = 'SimpleTest test body ' . $this->randomName(32) . ' ' . $this->randomName(32);
$langcode = FIELD_LANGUAGE_NONE;
$edit["body[$langcode][0][value]"] = 'SimpleTest test body ' . $this->randomName(32) . ' ' . $this->randomName(32);
$edit['book[bid]'] = $book_nid;
if ($parent !== NULL) {
......
......@@ -330,9 +330,10 @@ class DBLogTestCase extends DrupalWebTestCase {
break;
default:
$langcode = FIELD_LANGUAGE_NONE;
$content = array(
'title' => $this->randomName(8),
'body[0][value]' => $this->randomName(32),
"body[$langcode][0][value]" => $this->randomName(32),
);
break;
}
......@@ -355,8 +356,9 @@ class DBLogTestCase extends DrupalWebTestCase {
break;
default:
$langcode = FIELD_LANGUAGE_NONE;
$content = array(
'body[0][value]' => $this->randomName(32),
"body[$langcode][0][value]" => $this->randomName(32),
);
break;
}
......
......@@ -350,6 +350,8 @@ function hook_field_schema($field) {
* The field structure for the operation.
* @param $instances
* Array of instance structures for $field for each object, keyed by object id.
* @param $langcode
* The language associated to $items.
* @param $items
* Array of field values already loaded for the objects, keyed by object id.
* @param $age
......@@ -359,9 +361,7 @@ function hook_field_schema($field) {
* Changes or additions to field values are done by altering the $items
* parameter by reference.
*/
function hook_field_load($obj_type, $objects, $field, $instances, &$items, $age) {
global $language;
function hook_field_load($obj_type, $objects, $field, $instances, $langcode, &$items, $age) {
foreach ($objects as $id => $object) {
foreach ($items[$id] as $delta => $item) {
if (!empty($instances[$id]['settings']['text_processing'])) {
......@@ -369,10 +369,9 @@ function hook_field_load($obj_type, $objects, $field, $instances, &$items, $age)
// handled by hook_field_sanitize().
$format = $item['format'];
if (filter_format_allowcache($format)) {
$lang = isset($object->language) ? $object->language : $language->language;
$items[$id][$delta]['safe'] = isset($item['value']) ? check_markup($item['value'], $format, $lang, FALSE) : '';
$items[$id][$delta]['safe'] = isset($item['value']) ? check_markup($item['value'], $format, $langcode, FALSE) : '';
if ($field['type'] == 'text_with_summary') {
$items[$id][$delta]['safe_summary'] = isset($item['summary']) ? check_markup($item['summary'], $format, $lang, FALSE) : '';
$items[$id][$delta]['safe_summary'] = isset($item['summary']) ? check_markup($item['summary'], $format, $langcode, FALSE) : '';
}
}
}
......@@ -401,11 +400,12 @@ function hook_field_load($obj_type, $objects, $field, $instances, &$items, $age)
* The field structure for the operation.
* @param $instance
* The instance structure for $field on $object's bundle.
* @param $langcode
* The language associated to $items.
* @param $items
* $object->{$field['field_name']}, or an empty array if unset.
*/
function hook_field_sanitize($obj_type, $object, $field, $instance, $items) {
global $language;
function hook_field_sanitize($obj_type, $object, $field, $instance, $langcode, &$items) {
foreach ($items as $delta => $item) {
// Only sanitize items which were not already processed inside
// hook_field_load(), i.e. items with uncacheable text formats, or coming
......@@ -413,10 +413,9 @@ function hook_field_sanitize($obj_type, $object, $field, $instance, $items) {
if (!isset($items[$delta]['safe'])) {
if (!empty($instance['settings']['text_processing'])) {
$format = $item['format'];
$lang = isset($object->language) ? $object->language : $language->language;
$items[$delta]['safe'] = isset($item['value']) ? check_markup($item['value'], $format, $lang) : '';
$items[$delta]['safe'] = isset($item['value']) ? check_markup($item['value'], $format, $langcode) : '';
if ($field['type'] == 'text_with_summary') {
$items[$delta]['safe_summary'] = isset($item['summary']) ? check_markup($item['summary'], $format, $lang) : '';
$items[$delta]['safe_summary'] = isset($item['summary']) ? check_markup($item['summary'], $format, $langcode) : '';
}
}
else {
......@@ -444,8 +443,10 @@ function hook_field_sanitize($obj_type, $object, $field, $instance, $items) {
* The field structure for the operation.
* @param $instance
* The instance structure for $field on $object's bundle.
* @param $langcode
* The language associated to $items.
* @param $items
* $object->{$field['field_name']}, or an empty array if unset.
* $object->{$field['field_name']}[$langcode], or an empty array if unset.
* @param $errors
* The array of errors, keyed by field name and by value delta, that have
* already been reported for the object. The function should add its errors
......@@ -454,7 +455,7 @@ function hook_field_sanitize($obj_type, $object, $field, $instance, $items) {
* - 'error': an error code (should be a string, prefixed with the module name)
* - 'message': the human readable message to be displayed.
*/
function hook_field_validate($obj_type, $object, $field, $instance, $items, &$errors) {
function hook_field_validate($obj_type, $object, $field, $instance, $langcode, &$items, &$errors) {
foreach ($items as $delta => $item) {
if (!empty($item['value'])) {
if (!empty($field['settings']['max_length']) && drupal_strlen($item['value']) > $field['settings']['max_length']) {
......@@ -478,10 +479,12 @@ function hook_field_validate($obj_type, $object, $field, $instance, $items, &$er
* The field structure for the operation.
* @param $instance
* The instance structure for $field on $object's bundle.
* @param $langcode
* The language associated to $items.
* @param $items
* $object->{$field['field_name']}, or an empty array if unset.
* $object->{$field['field_name']}[$langcode], or an empty array if unset.
*/
function hook_field_presave($obj_type, $object, $field, $instance, $items) {
function hook_field_presave($obj_type, $object, $field, $instance, $langcode, &$items) {
}
/**
......@@ -495,10 +498,12 @@ function hook_field_presave($obj_type, $object, $field, $instance, $items) {
* The field structure for the operation.
* @param $instance
* The instance structure for $field on $object's bundle.
* @param $langcode
* The language associated to $items.
* @param $items
* $object->{$field['field_name']}, or an empty array if unset.
* $object->{$field['field_name']}[$langcode], or an empty array if unset.
*/
function hook_field_insert($obj_type, $object, $field, $instance, $items) {
function hook_field_insert($obj_type, $object, $field, $instance, $langcode, &$items) {
}
/**
......@@ -512,10 +517,12 @@ function hook_field_insert($obj_type, $object, $field, $instance, $items) {
* The field structure for the operation.
* @param $instance
* The instance structure for $field on $object's bundle.
* @param $langcode
* The language associated to $items.
* @param $items
* $object->{$field['field_name']}, or an empty array if unset.
* $object->{$field['field_name']}[$langcode], or an empty array if unset.
*/
function hook_field_update($obj_type, $object, $field, $instance, $items) {
function hook_field_update($obj_type, $object, $field, $instance, $langcode, &$items) {
}
/**
......@@ -531,10 +538,12 @@ function hook_field_update($obj_type, $object, $field, $instance, $items) {
* The field structure for the operation.
* @param $instance
* The instance structure for $field on $object's bundle.
* @param $langcode
* The language associated to $items.
* @param $items
* $object->{$field['field_name']}, or an empty array if unset.
* $object->{$field['field_name']}[$langcode], or an empty array if unset.
*/
function hook_field_delete($obj_type, $object, $field, $instance, $items) {
function hook_field_delete($obj_type, $object, $field, $instance, $langcode, &$items) {
}
/**
......@@ -551,10 +560,12 @@ function hook_field_delete($obj_type, $object, $field, $instance, $items) {
* The field structure for the operation.
* @param $instance
* The instance structure for $field on $object's bundle.
* @param $langcode
* The language associated to $items.
* @param $items
* $object->{$field['field_name']}, or an empty array if unset.
* $object->{$field['field_name']}[$langcode], or an empty array if unset.
*/
function hook_field_delete_revision($obj_type, $object, $field, $instance, $items) {
function hook_field_delete_revision($obj_type, $object, $field, $instance, $langcode, &$items) {
}
/**
......@@ -570,10 +581,12 @@ function hook_field_delete_revision($obj_type, $object, $field, $instance, $item
* The field structure for the operation.
* @param $instance
* The instance structure for $field on $object's bundle.
* @param $langcode
* The language associated to $items.
* @param $items
* $object->{$field['field_name']}, or an empty array if unset.
* $object->{$field['field_name']}[$langcode], or an empty array if unset.
*/
function hook_field_prepare_translation($obj_type, $object, $field, $instance, $items) {
function hook_field_prepare_translation($obj_type, $object, $field, $instance, $langcode, &$items) {
}
/**
......@@ -902,7 +915,7 @@ function theme_field_formatter_FORMATTER_MULTIPLE($element) {
*
* See field_attach_form() for details and arguments.
*/
function hook_field_attach_form($obj_type, $object, &$form, &$form_state) {
function hook_field_attach_form($obj_type, $object, &$form, &$form_state, $langcode) {
}
/**
......@@ -987,6 +1000,23 @@ function hook_field_attach_submit($obj_type, $object, $form, &$form_state) {
function hook_field_attach_presave($obj_type, $object) {
}
/**
* Act on field_attach_preprocess.
*
* This hook is invoked while preprocessing the field.tpl.php template file.
*
* @param $variables
* The variables array is passed by reference and will be populated with field values.
* @param $obj_type
* The type of $object; e.g. 'node' or 'user'.
* @param $object
* The object with fields to render.
* @param $element
* The structured array containing the values ready for rendering.
*/
function hook_field_attach_preprocess_alter(&$variables, $obj_type, $object, $element) {
}
/**
* Act on field_attach_insert.
*
......@@ -1094,8 +1124,10 @@ function hook_field_attach_delete_revision($obj_type, $object) {
* The object with fields to render.
* @param $build_mode
* Build mode, e.g. 'full', 'teaser'...
* @param $langcode
* The language in which the field values will be displayed.
*/
function hook_field_attach_view_alter($output, $obj_type, $object, $build_mode) {
function hook_field_attach_view_alter($output, $obj_type, $object, $build_mode, $langcode) {
}
/**
......
This diff is collapsed.
......@@ -46,6 +46,8 @@
* - cardinality (integer)
* The number of values the field can hold. Legal values are any
* positive integer or FIELD_CARDINALITY_UNLIMITED.
* - translatable (integer)
* Whether the field is translatable.
* - locked (integer)
* TODO: undefined.
* - module (string, read-only)
......@@ -237,6 +239,7 @@ function field_create_field($field) {
$field += array(
'cardinality' => 1,
'translatable' => FALSE,
'locked' => FALSE,
'settings' => array(),
);
......
......@@ -11,17 +11,17 @@
* the corresponding field_attach_[operation]() function.
*/
function field_default_extract_form_values($obj_type, $object, $field, $instance, &$items, $form, &$form_state) {
function field_default_extract_form_values($obj_type, $object, $field, $instance, $langcode, &$items, $form, &$form_state) {
$field_name = $field['field_name'];
if (isset($form_state['values'][$field_name])) {
$items = $form_state['values'][$field_name];
if (isset($form_state['values'][$field_name][$langcode])) {
$items = $form_state['values'][$field_name][$langcode];
// Remove the 'value' of the 'add more' button.
unset($items[$field_name . '_add_more']);
}
}
function field_default_submit($obj_type, $object, $field, $instance, &$items, $form, &$form_state) {
function field_default_submit($obj_type, $object, $field, $instance, $langcode, &$items, $form, &$form_state) {
$field_name = $field['field_name'];
// Reorder items to account for drag-n-drop reordering.
......@@ -40,19 +40,25 @@ function field_default_submit($obj_type, $object, $field, $instance, &$items, $f
* This can happen with programmatic saves, or on form-based creation where
* the current user doesn't have 'edit' permission for the field.
*/
function field_default_insert($obj_type, $object, $field, $instance, &$items) {
function field_default_insert($obj_type, $object, $field, $instance, $langcode, &$items) {
// _field_invoke() populates $items with an empty array if the $object has no
// entry for the field, so we check on the $object itself.
if (empty($object) || !property_exists($object, $field['field_name'])) {
$items = field_get_default_value($obj_type, $object, $field, $instance);
// We also check that the current field translation is actually defined before
// assigning it a default value. This way we ensure that only the intended
// languages get a default value. Otherwise we could have default values for
// not yet open languages.
if (empty($object) || !property_exists($object, $field['field_name']) ||
(isset($object->{$field['field_name']}[$langcode]) && count($object->{$field['field_name']}[$langcode]) == 0)) {
$items = field_get_default_value($obj_type, $object, $field, $instance, $langcode);
}
}
/**
* Default field 'view' operation.
*
* @see field_attach_view()
*/
function field_default_view($obj_type, $object, $field, $instance, $items, $build_mode) {
function field_default_view($obj_type, $object, $field, $instance, $langcode, $items, $build_mode) {
list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
$addition = array();
......@@ -82,6 +88,7 @@ function field_default_view($obj_type, $object, $field, $instance, $items, $buil
'#label_display' => $label_display,
'#build_mode' => $build_mode,
'#single' => $single,
'#language' => $langcode,
'items' => array(),
);
......@@ -117,7 +124,7 @@ function field_default_view($obj_type, $object, $field, $instance, $items, $buil
return $addition;
}
function field_default_prepare_translation($obj_type, $object, $field, $instance, &$items) {
function field_default_prepare_translation($obj_type, $object, $field, $instance, $langcode, &$items) {
$addition = array();
if (isset($object->translation_source->$field['field_name'])) {
$addition[$field['field_name']] = $object->translation_source->$field['field_name'];
......
......@@ -9,7 +9,7 @@
/**
* Create a separate form element for each field.
*/
function field_default_form($obj_type, $object, $field, $instance, $items, &$form, &$form_state, $get_delta = NULL) {
function field_default_form($obj_type, $object, $field, $instance, $langcode, $items, &$form, &$form_state, $get_delta = NULL) {
// This could be called with no object, as when a UI module creates a
// dummy form to set default values.
if ($object) {
......@@ -48,7 +48,7 @@ function field_default_form($obj_type, $object, $field, $instance, $items, &$for
// and we are displaying an individual element, process the multiple value
// form.
if (!isset($get_delta) && field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_DEFAULT) {
$form_element = field_multiple_value_form($field, $instance, $items, $form, $form_state);
$form_element = field_multiple_value_form($field, $instance, $langcode, $items, $form, $form_state);
}
// If the widget is handling multiple values (e.g Options),
// or if we are displaying an individual element, just get a single form
......@@ -89,7 +89,20 @@ function field_default_form($obj_type, $object, $field, $instance, $items, &$for
'#weight' => $instance['widget']['weight'],
);
$addition[$field['field_name']] = array_merge($form_element, $defaults);
$form_element = array_merge($form_element, $defaults);
// Add the field form element as a child keyed by language code to match the
// field data structure: $object->{$field_name}[$langcode][$delta][$column].
// The '#language' key can be used to access the field's form element when
// $langcode is unknown. The #weight property is inherited from the field's
// form element.
$addition[$field['field_name']] = array(
'#tree' => TRUE,
'#weight' => $form_element['#weight'],
'#language' => $langcode,
$langcode => $form_element,
);
$form['#fields'][$field['field_name']]['form_path'] = array($field['field_name']);
}
......@@ -104,7 +117,7 @@ function field_default_form($obj_type, $object, $field, $instance, $items, &$for
* - AHAH-'add more' button
* - drag-n-drop value reordering
*/
function field_multiple_value_form($field, $instance, $items, &$form, &$form_state) {
function field_multiple_value_form($field, $instance, $langcode, $items, &$form, &$form_state) {
$field = field_info_field($instance['field_name']);
$field_name = $field['field_name'];
......@@ -197,9 +210,11 @@ function field_multiple_value_form($field, $instance, $items, &$form, &$form_sta
'#field_name' => $field_name,
'#bundle' => $instance['bundle'],
'#attributes' => array('class' => 'field-add-more-submit'),
'#language' => $langcode,
);
}
}
return $form_element;
}
......@@ -276,9 +291,9 @@ function theme_field_multiple_value_form($element) {
/**
* Transfer field-level validation errors to widgets.
*/
function field_default_form_errors($obj_type, $object, $field, $instance, $items, $form, $errors) {
function field_default_form_errors($obj_type, $object, $field, $instance, $langcode, $items, $form, $errors) {
$field_name = $field['field_name'];
if (!empty($errors[$field_name])) {
if (!empty($errors[$field_name][$langcode])) {
$function = $instance['widget']['module'] . '_field_widget_error';
$function_exists = drupal_function_exists($function);
......@@ -290,10 +305,10 @@ function field_default_form_errors($obj_type, $object, $field, $instance, $items
}
$multiple_widget = field_behaviors_widget('multiple values', $instance) != FIELD_BEHAVIOR_DEFAULT;
foreach ($errors[$field_name] as $delta => $delta_errors) {
foreach ($errors[$field_name][$langcode] as $delta => $delta_errors) {
// For multiple single-value widgets, pass errors by delta.
// For a multiple-value widget, all errors are passed to the main widget.
$error_element = $multiple_widget ? $element : $element[$delta];
$error_element = $multiple_widget ? $element[$langcode] : $element[$langcode][$delta];
foreach ($delta_errors as $error) {
if ($function_exists) {
$function($error_element, $error);
......@@ -320,8 +335,9 @@ function field_add_more_submit($form, &$form_state) {
// Make the changes we want to the form state.
$field_name = $form_state['clicked_button']['#field_name'];
$langcode = $form_state['clicked_button']['#language'];
if ($form_state['values'][$field_name . '_add_more']) {
$form_state['field_item_count'][$field_name] = count($form_state['values'][$field_name]);
$form_state['field_item_count'][$field_name] = count($form_state['values'][$field_name][$langcode]);
}
}
}
......@@ -383,19 +399,25 @@ function field_add_more_js($bundle_name, $field_name) {
// Reset cached ids, so that they don't affect the actual form we output.
drupal_static_reset('form_clean_id');
// Ensure that a valid language is provided.
$langcode = key($_POST[$field_name]);
if ($langcode != FIELD_LANGUAGE_NONE) {
$langcode = field_multilingual_valid_language($langcode);
}
// Sort the $form_state['values'] we just built *and* the incoming $_POST data
// according to d-n-d reordering.
unset($form_state['values'][$field_name][$field['field_name'] . '_add_more']);
foreach ($_POST[$field_name] as $delta => $item) {
$form_state['values'][$field_name][$delta]['_weight'] = $item['_weight'];
unset($form_state['values'][$field_name][$langcode][$field['field_name'] . '_add_more']);
foreach ($_POST[$field_name][$langcode] as $delta => $item) {
$form_state['values'][$field_name][$langcode][$delta]['_weight'] = $item['_weight'];
}
$form_state['values'][$field_name] = _field_sort_items($field, $form_state['values'][$field_name]);
$_POST[$field_name] = _field_sort_items($field, $_POST[$field_name]);
$form_state['values'][$field_name][$langcode] = _field_sort_items($field, $form_state['values'][$field_name][$langcode]);
$_POST[$field_name][$langcode] = _field_sort_items($field, $_POST[$field_name][$langcode]);
// Build our new form element for the whole field, asking for one more element.
$form_state['field_item_count'] = array($field_name => count($_POST[$field_name]) + 1);
$items = $form_state['values'][$field_name];
$form_element = field_default_form(NULL, NULL, $field, $instance, $items, $form, $form_state);
$form_state['field_item_count'] = array($field_name => count($_POST[$field_name][$langcode]) + 1);
$items = $form_state['values'][$field_name][$langcode];
$form_element = field_default_form(NULL, NULL, $field, $instance, $langcode, $items, $form, $form_state);
// Let other modules alter it.
drupal_alter('form', $form_element, array(), 'field_add_more_js');
......@@ -412,8 +434,8 @@ function field_add_more_js($bundle_name, $field_name) {
// Build the new form against the incoming $_POST values so that we can
// render the new element.
$delta = max(array_keys($_POST[$field_name])) + 1;
$_POST[$field_name][$delta]['_weight'] = $delta;
$delta = max(array_keys($_POST[$field_name][$langcode])) + 1;
$_POST[$field_name][$langcode][$delta]['_weight'] = $delta;
$form_state = form_state_defaults();
$form_state['input'] = $_POST;
$form = form_builder($_POST['form_id'], $form, $form_state);
......
......@@ -9,6 +9,7 @@ files[] = field.install
files[] = field.crud.inc
files[] = field.info.inc
files[] = field.default.inc
files[] = field.multilingual.inc
files[] = field.attach.inc
files[] = field.form.inc
files[] = field.test
......
......@@ -130,6 +130,7 @@ function _field_info_collate_types($reset = FALSE) {
// Provide defaults.
$fieldable_info += array(
'cacheable' => TRUE,
'translation_handlers' => array(),
'bundles' => array(),
);
$fieldable_info['object keys'] += array(
......
......@@ -63,6 +63,12 @@ function field_schema() {
'not null' => TRUE,
'default' => 0,
),
'translatable' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'active' => array(
'type' => 'int',
'size' => 'tiny',
......
......@@ -12,6 +12,7 @@
*/
require(DRUPAL_ROOT . '/modules/field/field.crud.inc');
require(DRUPAL_ROOT . '/modules/field/field.info.inc');
require(DRUPAL_ROOT . '/modules/field/field.multilingual.inc');
require(DRUPAL_ROOT . '/modules/field/field.attach.inc');
/**
......@@ -66,6 +67,13 @@
*/
define('FIELD_CARDINALITY_UNLIMITED', -1);
/**
* The language code assigned to untranslatable fields.
*
* Defined by ISO639-2 for "No linguistic content / Not applicable".
*/
define('FIELD_LANGUAGE_NONE', 'zxx');
/**
* TODO
*/
......@@ -274,13 +282,15 @@ function field_associate_fields($module) {
* The field structure.
* @param $instance
* The instance structure.
* @param $langcode
* The field language to fill-in with the default value.
*/
function field_get_default_value($obj_type, $object, $field, $instance) {
function field_get_default_value($obj_type, $object, $field, $instance, $langcode = NULL) {
$items = array();
if (!empty($instance['default_value_function'])) {