security update core+modules
This commit is contained in:
53
sites/all/modules/i18n/i18n_field/i18n_field.api.php
Normal file
53
sites/all/modules/i18n/i18n_field/i18n_field.api.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* API documentation file for Field translation module.
|
||||
*
|
||||
* This module takes care of translating common field elements like title and
|
||||
* description for all fields, plus some field specific values (default, options)
|
||||
* for field types defined by Drupal core.
|
||||
*
|
||||
* Before implementing any of these hooks, consider whether you would be better
|
||||
* off implementing Drupal core's hook_field_widget_form_alter().
|
||||
*
|
||||
* @see i18n_field_field_widget_form_alter()
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provide information about callbacks for translating specific field types.
|
||||
*
|
||||
* This information can be retrieved using i18n_field_type_info().
|
||||
* @return
|
||||
* Array of values indexed by field type. Valid keys are:
|
||||
* - 'translate_default', Callback for translating the default value for this field type.
|
||||
* - 'translate_options', Callback for translating options for this field type.
|
||||
*
|
||||
* @see i18n_field_type_info()
|
||||
* @see i18n_field_i18n_field_info()
|
||||
*
|
||||
* For examples of both callback types:
|
||||
*
|
||||
* @see i18n_field_translate_allowed_values()
|
||||
* @see i18n_field_translate_default()
|
||||
*
|
||||
*/
|
||||
function hook_i18n_field_info() {
|
||||
$info['text'] = $info['text_long'] = $info['text_with_summary'] = array(
|
||||
'translate_default' => 'i18n_field_translate_default',
|
||||
);
|
||||
$info['list_text'] = $info['list_boolean'] = $info['list_integer'] = array(
|
||||
'translate_options' => 'i18n_field_translate_allowed_values',
|
||||
);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter information provided by hook_i18n_field_info().
|
||||
*
|
||||
* @see i18n_field_type_info()
|
||||
*/
|
||||
function hook_i18n_field_info_alter(&$info) {
|
||||
// Unset the default callback for text fields.
|
||||
unset($info['text']['translate_default']);
|
||||
}
|
@@ -72,6 +72,7 @@ function i18n_field_i18n_string_info() {
|
||||
'description' => t('Configurable fields descriptions, defaults, options, etc.'),
|
||||
'format' => FALSE, // This group doesn't have formatted strings
|
||||
'list' => TRUE, // This group can list all strings
|
||||
'class' => 'i18n_string_textgroup_cached',
|
||||
);
|
||||
return $groups;
|
||||
}
|
||||
|
@@ -6,9 +6,9 @@ package = Multilingual - Internationalization
|
||||
core = 7.x
|
||||
files[] = i18n_field.inc
|
||||
files[] = i18n_field.test
|
||||
; Information added by drupal.org packaging script on 2013-01-13
|
||||
version = "7.x-1.8"
|
||||
; Information added by Drupal.org packaging script on 2015-01-26
|
||||
version = "7.x-1.12"
|
||||
core = "7.x"
|
||||
project = "i18n"
|
||||
datestamp = "1358075001"
|
||||
datestamp = "1422286982"
|
||||
|
||||
|
@@ -163,7 +163,6 @@ function i18n_field_field_formatter_view($entity_type, $entity, $field, $instanc
|
||||
return $element;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_field_widget_form_alter().
|
||||
*
|
||||
@@ -176,8 +175,8 @@ function i18n_field_field_formatter_view($entity_type, $entity, $field, $instanc
|
||||
function i18n_field_field_widget_form_alter(&$element, &$form_state, $context) {
|
||||
global $language;
|
||||
|
||||
// Skip the node type edit fields by checking for existing entity
|
||||
if (empty($element['#entity'])) {
|
||||
// Don't translate if the widget is being shown on the field edit form.
|
||||
if ($form_state['build_info']['form_id'] == 'field_ui_field_edit_form') {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -189,8 +188,38 @@ function i18n_field_field_widget_form_alter(&$element, &$form_state, $context) {
|
||||
$instance = $context['instance'];
|
||||
$langcode = $context['langcode'];
|
||||
|
||||
// Get the element to alter. Account for inconsistencies in how the element
|
||||
// is built for different field types.
|
||||
if (isset($element[0]) && count($element) == 1) {
|
||||
// Single-value file fields and image fields.
|
||||
$alter_element = &$element[0];
|
||||
}
|
||||
elseif (isset($element['value'])) {
|
||||
// Number fields. Single-value text fields.
|
||||
$alter_element = &$element['value'];
|
||||
}
|
||||
elseif ($field['type'] == 'entityreference' && isset($element['target_id'])) {
|
||||
// Entityreference fields using the entityreference_autocomplete widget.
|
||||
$alter_element = &$element['target_id'];
|
||||
}
|
||||
else {
|
||||
// All other fields.
|
||||
$alter_element = &$element;
|
||||
}
|
||||
|
||||
// If a subelement has the same title as the parent, translate it instead.
|
||||
// Allows fields such as email and commerce_price to be translated.
|
||||
foreach (element_get_visible_children($element) as $key) {
|
||||
$single_value = ($field['cardinality'] == 1);
|
||||
$has_title = (isset($element['#title']) && isset($element[$key]['#title']));
|
||||
if ($single_value && $has_title && $element[$key]['#title'] == $element['#title']) {
|
||||
$alter_element = &$element[$key];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// The field language may affect some variables (default) but not others (description will be in current page language)
|
||||
$i18n_langcode = empty($element['#language']) || $element['#language'] == LANGUAGE_NONE ? $language->language : $element['#language'];
|
||||
$i18n_langcode = empty($alter_element['#language']) || $alter_element['#language'] == LANGUAGE_NONE ? $language->language : $alter_element['#language'];
|
||||
|
||||
// Translate instance to current page language and set to form_state
|
||||
// so it will be used for validation messages later.
|
||||
@@ -200,37 +229,60 @@ function i18n_field_field_widget_form_alter(&$element, &$form_state, $context) {
|
||||
}
|
||||
|
||||
// Translate field title if set and it is the default one.
|
||||
// When cardinality is 1, $element['value'] is used instead.
|
||||
if (!empty($instance_current['label']) && $instance_current['label'] != $instance['label']) {
|
||||
if (!empty($element['#title']) && $element['#title'] == $instance['label']) {
|
||||
$element['#title'] = $instance_current['label'];
|
||||
}
|
||||
if (isset($element['value']) && !empty($element['value']['#title']) && $element['value']['#title'] == $instance['label']) {
|
||||
$element['value']['#title'] = $instance_current['label'];
|
||||
if (!empty($alter_element['#title']) && $alter_element['#title'] == check_plain($instance['label'])) {
|
||||
$alter_element['#title'] = check_plain($instance_current['label']);
|
||||
}
|
||||
}
|
||||
|
||||
// Translate field description if set and it is the default one.
|
||||
// When cardinality is 1, $element['value'] is used instead.
|
||||
if (!empty($instance_current['description']) && $instance_current['description'] != $instance['description']) {
|
||||
if (!empty($element['#description']) && $element['#description'] == $instance['description']) {
|
||||
$element['#description'] = $instance_current['description'];
|
||||
}
|
||||
if (isset($element['value']) && !empty($element['value']['#description']) && $element['value']['#description'] == $instance['description']) {
|
||||
$element['value']['#description'] = $instance_current['description'];
|
||||
if (!empty($alter_element['#description'])) {
|
||||
// Allow single-value file fields and image fields to have their
|
||||
// descriptions translated. file_field_widget_form() passes the
|
||||
// description through theme('file_upload_help'), so i18n_field
|
||||
// must do the same.
|
||||
$filefield = in_array($field['type'], array('file', 'image'));
|
||||
$single_value = ($field['cardinality'] == 1);
|
||||
$no_default = empty($alter_element['#default_value']['fid']);
|
||||
if ($filefield && $single_value && $no_default) {
|
||||
$help_variables = array(
|
||||
'description' => field_filter_xss($instance['description']),
|
||||
'upload_validators' => isset($alter_element['#upload_validators']) ? $alter_element['#upload_validators'] : array(),
|
||||
);
|
||||
$original_description = theme('file_upload_help', $help_variables);
|
||||
if ($alter_element['#description'] == $original_description) {
|
||||
$help_variables = array(
|
||||
'description' => field_filter_xss($instance_current['description']),
|
||||
'upload_validators' => isset($alter_element['#upload_validators']) ? $alter_element['#upload_validators'] : array(),
|
||||
);
|
||||
$alter_element['#description'] = theme('file_upload_help', $help_variables);
|
||||
}
|
||||
}
|
||||
elseif ($alter_element['#description'] == field_filter_xss($instance['description'])) {
|
||||
$alter_element['#description'] = field_filter_xss($instance_current['description']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Translate list options
|
||||
if (!empty($element['#options']) && ($translate = i18n_field_type_info($field['type'], 'translate_options')) && !empty($field['settings']['allowed_values'])) {
|
||||
$element['#options'] = $translate($field, $i18n_langcode);
|
||||
if (isset($element['#properties']) && !empty($element['#properties']['empty_option'])) {
|
||||
$label = theme('options_none', array('instance' => $instance, 'option' => $element['#properties']['empty_option']));
|
||||
$element['#options'] = array('_none' => $label) + $element['#options'];
|
||||
// For some elements, change title to new translated option
|
||||
if (!empty($element['#title']) && $field['type'] == 'list_boolean' && !empty($element['#on_value'])) {
|
||||
$on_value = $element['#on_value'];
|
||||
$element['#title'] = $element['#options'][$on_value];
|
||||
// Translate list options.
|
||||
$has_options = (!empty($alter_element['#options']) || $field['type'] == 'list_boolean');
|
||||
$has_allowed_values = !empty($field['settings']['allowed_values']);
|
||||
$translate = i18n_field_type_info($field['type'], 'translate_options');
|
||||
if ($has_options && $has_allowed_values && $translate) {
|
||||
$alter_element['#options'] = $translate($field, $i18n_langcode);
|
||||
if (isset($alter_element['#properties']) && !empty($alter_element['#properties']['empty_option'])) {
|
||||
$label = theme('options_none', array('instance' => $instance, 'option' => $alter_element['#properties']['empty_option']));
|
||||
$alter_element['#options'] = array('_none' => $label) + $alter_element['#options'];
|
||||
}
|
||||
// Translate list_boolean fields using the checkboxes widget.
|
||||
if (!empty($alter_element['#title']) && $field['type'] == 'list_boolean' && !empty($alter_element['#on_value'])) {
|
||||
$on_value = $alter_element['#on_value'];
|
||||
$alter_element['#options'];
|
||||
$alter_element['#title'] = $alter_element['#options'][$on_value];
|
||||
// For using label instead of "On value".
|
||||
if ($instance['widget']['settings']['display_label']) {
|
||||
$alter_element['#title'] = $instance_current['label'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -242,11 +294,15 @@ function i18n_field_field_widget_form_alter(&$element, &$form_state, $context) {
|
||||
$delta = $context['delta'];
|
||||
$items = $context['items'];
|
||||
|
||||
// Translate default value if exists and the current value is the default
|
||||
if (isset($element['value']['#default_value']) && ($translate = i18n_field_type_info($field['type'], 'translate_default')) &&
|
||||
!empty($instance['default_value'][$delta]['value']) && !empty($items[$delta]['value']) &&
|
||||
$instance['default_value'][$delta]['value'] === $items[$delta]['value']) {
|
||||
$element['value']['#default_value'] = $translate($instance, $items[$delta]['value'], $i18n_langcode);
|
||||
// Translate default value.
|
||||
$has_default_value = (isset($alter_element['#default_value']) && !empty($instance['default_value'][$delta]['value']));
|
||||
$storage_has_value = !empty($items[$delta]['value']);
|
||||
$translate = i18n_field_type_info($field['type'], 'translate_default');
|
||||
if ($has_default_value && $storage_has_value && $translate) {
|
||||
// Compare the default value with the value currently in storage.
|
||||
if ($instance['default_value'][$delta]['value'] === $items[$delta]['value']) {
|
||||
$alter_element['#default_value'] = $translate($instance, $items[$delta]['value'], $i18n_langcode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,10 +400,12 @@ function i18n_field_translate_allowed_values($field, $langcode = NULL) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate field default
|
||||
* Translate field default.
|
||||
*/
|
||||
function i18n_field_translate_default($instance, $value, $langcode = NULL) {
|
||||
return i18n_string_translate(array('field', $instance['field_name'], $instance['bundle'], 'default_value'), $value, array('langcode' => $langcode));
|
||||
// The default value does not need sanitizing in a text_textfield widget.
|
||||
$sanitize = !($instance['widget']['type'] == 'text_textfield' && $instance['widget']['module'] == 'text');
|
||||
return i18n_string_translate(array('field', $instance['field_name'], $instance['bundle'], 'default_value'), $value, array('langcode' => $langcode, 'sanitize' => $sanitize));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -360,7 +418,17 @@ function i18n_field_translate_property($instance, $property, $langcode = NULL) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get i18n information for fields
|
||||
* Get i18n information for translating fields.
|
||||
*
|
||||
* @param $type
|
||||
* Optional field type.
|
||||
* @param $property
|
||||
* Optional property to get from field type.
|
||||
*
|
||||
* @return
|
||||
* - The property for the field if $type and $property set.
|
||||
* - Array of properties for the field type if only $type is set.
|
||||
* - Array of translation information for all field types.
|
||||
*/
|
||||
function i18n_field_type_info($type = NULL, $property = NULL) {
|
||||
$info = &drupal_static(__FUNCTION__);
|
||||
|
Reference in New Issue
Block a user