Révision b3ab3446
Ajouté par Assos Assos il y a plus de 7 ans
drupal7/sites/all/modules/i18n/i18n_field/i18n_field.module | ||
---|---|---|
446 | 446 |
return $info; |
447 | 447 |
} |
448 | 448 |
} |
449 |
|
|
450 |
/** |
|
451 |
* Implements hook_field_info_alter(). |
|
452 |
*/ |
|
453 |
function i18n_field_field_info_alter(&$field_info) { |
|
454 |
foreach(array_keys($field_info) as $type) { |
|
455 |
$field_info[$type]['property_callbacks'][] = 'i18n_field_entity_property_callback'; |
|
456 |
} |
|
457 |
} |
|
458 |
|
|
459 |
/** |
|
460 |
* Callback to translate entity property info for a fields. |
|
461 |
* |
|
462 |
* @see entity_metadata_field_entity_property_info() |
|
463 |
* @see entity_metadata_field_default_property_callback() |
|
464 |
* @see i18n_field_i18n_object_info_alter() |
|
465 |
* @see hook_module_implements_alter() |
|
466 |
*/ |
|
467 |
function i18n_field_entity_property_callback(&$info, $entity_type, $field, $instance, $field_type) { |
|
468 |
global $language; |
|
469 |
|
|
470 |
// This could create a endless recursion if it's called during rebuilding the |
|
471 |
// cache for i18n_object_info(). So if the cache of i18n_object_info isn't |
|
472 |
// available yet we assume the worst case, leave the info alone but trigger a |
|
473 |
// rebuild of the property when hook_i18n_object_info_alter is invoked. At |
|
474 |
// that point the info is available and we can rely on it. |
|
475 |
if (!$info = &drupal_static('i18n_object_info')) { |
|
476 |
$i18n_field_entity_property_callback_fallback = &drupal_static(__FUNCTION__); |
|
477 |
$i18n_field_entity_property_callback_fallback = TRUE; |
|
478 |
return; |
|
479 |
} |
|
480 |
|
|
481 |
$name = $field['field_name']; |
|
482 |
$property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$name]; |
|
483 |
$property['label'] = i18n_field_translate_property($instance, 'label', $language->language); |
|
484 |
} |
|
485 |
|
|
486 |
/** |
|
487 |
* Implements hook_i18n_object_info_alter(). |
|
488 |
*/ |
|
489 |
function i18n_field_i18n_object_info_alter(&$info) { |
|
490 |
if (drupal_static('i18n_field_entity_property_callback')) { |
|
491 |
if ($info = drupal_static('i18n_object_info')) { |
|
492 |
// Clean static and permanent cache of the data and then re-run the property |
|
493 |
// building. |
|
494 |
drupal_static_reset('entity_get_property_info'); |
|
495 |
cache_clear_all('entity_property_info:' . $GLOBALS['language']->language, 'cache'); |
|
496 |
entity_get_property_info(); |
|
497 |
} |
|
498 |
else { |
|
499 |
watchdog('i18n_field', 'Unable to run fall-back handling for entity property translation due missing "i18n_object_info" cache', array(), WATCHDOG_WARNING); |
|
500 |
} |
|
501 |
} |
|
502 |
} |
|
503 |
|
|
504 |
/** |
|
505 |
* Implements hook_module_implements_alter(). |
|
506 |
*/ |
|
507 |
function i18n_field_module_implements_alter(&$implementations, $hook) { |
|
508 |
if ($hook == 'i18n_object_info_alter') { |
|
509 |
// Move our hook implementation to the bottom. |
|
510 |
$group = $implementations['i18n_field']; |
|
511 |
unset($implementations['i18n_field']); |
|
512 |
$implementations['i18n_field'] = $group; |
|
513 |
} |
|
514 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules