function i18n_field_i18n_object_info_alter in Internationalization 7
Implements hook_i18n_object_info_alter().
File
- i18n_field/
i18n_field.module, line 522 - Internationalization (i18n) module - Field handling
Code
function i18n_field_i18n_object_info_alter(&$info) {
if (drupal_static('i18n_field_entity_property_callback')) {
if ($info = drupal_static('i18n_object_info')) {
// Clean static and permanent cache of the data and then re-run the property
// building.
// Use a lock to avoid stampeding.
$lock_name = 'i18n_field_entity_property_callback_fallback:' . $GLOBALS['language']->language;
// See if another request is already doing this. If so we bail out here as
// we won't help with anything at the moment.
if (!lock_may_be_available($lock_name)) {
return;
}
if (lock_acquire($lock_name)) {
i18n_field_prime_caches();
// Inject translated properties.
$entity_property_info = entity_get_property_info();
foreach ($entity_property_info as $entity_type => $properties) {
if (isset($properties['bundles'])) {
foreach ($properties['bundles'] as $bundle => $bundle_properties) {
if ($bundle_properties['properties']) {
foreach ($bundle_properties['properties'] as $bundle_property => $bundle_property_info) {
if ($instance = field_info_instance($entity_type, $bundle_property, $bundle)) {
$property =& $entity_property_info[$entity_type]['bundles'][$instance['bundle']]['properties'][$bundle_property];
$property['label'] = i18n_field_translate_property($instance, 'label', $GLOBALS['language']->language);
}
}
}
}
}
}
// Inject into static cache.
$entity_get_property_info =& drupal_static('entity_get_property_info', array());
$entity_get_property_info = $entity_property_info;
// Write permanent cache.
cache_set('entity_property_info:' . $GLOBALS['language']->language, $entity_property_info);
lock_release($lock_name);
}
}
else {
watchdog('i18n_field', 'Unable to run fall-back handling for entity property translation due missing "i18n_object_info" cache', array(), WATCHDOG_WARNING);
}
}
}