public static function LocalizeFields::preprocessFieldMultipleValueForm in Localize Fields 7
Translates instance wrapper label and description when any/more values (cardinality not 1).
Implements hook_preprocess_HOOK(). Implements hook_preprocess_field_multiple_value_form().
Is executed right after hook_field_widget_form_alter().
Parameters
array &$variables:
See also
localize_fields_preprocess_field_multiple_value_form()
1 call to LocalizeFields::preprocessFieldMultipleValueForm()
- localize_fields_preprocess_field_multiple_value_form in ./
localize_fields.module - Translates instance wrapper label and description when any/more values (cardinality not 1).
File
- ./
LocalizeFields.inc, line 594 - Drupal Localize Fields module
Class
- LocalizeFields
- @file Drupal Localize Fields module
Code
public static function preprocessFieldMultipleValueForm(&$variables) {
if (($localize = self::$localize) == -1) {
// Save a method call if possible.
$localize = self::localize();
}
if (!$localize) {
return;
}
if (!empty($variables['element'][0])) {
$element =& $variables['element'];
if ((!empty($element['#title']) || !empty($element['#description'])) && !empty($element['#field_name'])) {
$field_name = $element['#field_name'];
// The hardest part is finding entity type and bundle.
if (!empty($element[0]['#entity_type']) && !empty($element[0]['#bundle'])) {
$entity_type = $element[0]['#entity_type'];
$bundle = $element[0]['#bundle'];
}
elseif (!empty($element[0]['value']['#entity_type']) && !empty($element[0]['value']['#bundle'])) {
$entity_type = $element[0]['value']['#entity_type'];
$bundle = $element[0]['value']['#bundle'];
}
else {
unset($element);
// Clear ref.
return;
}
// field_collection is called 'field_collection_item' in this context.
// field_collection_item always reports itself as bundle.
if ($bundle == $field_name) {
if (!empty($variables['element']['#field_parents'][0])) {
$bundle = $variables['element']['#field_parents'][0];
}
// field_collection_item will also reports it's parent as itself
// when attached directly to entity/node (not nested in another
// field collection).
if ($bundle == $field_name) {
// Use the fallbacks set by the field_widget_form_alter.
// The reason this works is that the field collection itself always
// gets processed after it's children - thus the last field that set
// these properties must be attached directly to the root entity/node.
$entity_type = self::$lastKnownEntityType;
$bundle = self::$lastKnownBundle;
}
}
$instanceInfo = field_info_instance($entity_type, $field_name, $bundle);
if ($instanceInfo) {
$context_instance = 'field_instance' . self::CONTEXT_DELIMITER . $bundle . self::CONTEXT_DELIMITER_BUNDLE . $field_name . self::CONTEXT_DELIMITER;
if (!empty($instanceInfo['label'])) {
$element['#title'] = check_plain(self::translateInternal($instanceInfo['label'], $context_instance . 'label', TRUE));
}
if (!empty($instanceInfo['description'])) {
$element['#description'] = field_filter_xss(self::translateInternal($instanceInfo['description'], $context_instance . 'description', FALSE));
}
}
// 'Add another item' button label, if multi-cardinal.
if (!empty($element['add_more']['#value'])) {
$fieldInfo = field_info_field($field_name);
if ($fieldInfo && !empty($fieldInfo['settings']['add_row_localization_source'])) {
$element['add_more']['#value'] = field_filter_xss(self::translateInternal($fieldInfo['settings']['add_row_localization_source'], 'field' . self::CONTEXT_DELIMITER . $field_name . self::CONTEXT_DELIMITER . 'add_row', FALSE));
}
}
}
unset($element);
// Clear ref.
}
// There's another description in $variables['element'][0]['#description']
// but haven't found a field type that gets that one rendered.
}