entity_test_i18n.module 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * @file
  4. * Entity-test i18n integration module via entity API i18n support.
  5. *
  6. * @see EntityDefaultI18nController
  7. */
  8. /**
  9. * Implements hook_entity_info_alter().
  10. */
  11. function entity_test_i18n_entity_info_alter(&$info) {
  12. // Enable i18n support via the entity API.
  13. $info['entity_test_type']['i18n controller class'] = 'EntityDefaultI18nStringController';
  14. }
  15. /**
  16. * Implements hook_entity_property_info_alter().
  17. */
  18. function entity_test_i18n_entity_property_info_alter(&$info) {
  19. // Mark some properties as translatable, but also denote that translation
  20. // works with i18n_string.
  21. foreach (array('label') as $name) {
  22. $info['entity_test_type']['properties'][$name]['translatable'] = TRUE;
  23. $info['entity_test_type']['properties'][$name]['i18n string'] = TRUE;
  24. }
  25. }
  26. /**
  27. * Implements hook_{entity_test_type}_insert().
  28. */
  29. function entity_test_i18n_entity_test_type_insert($test_type) {
  30. i18n_string_object_update('entity_test_type', $test_type);
  31. }
  32. /**
  33. * Implements hook_{entity_test_type}_update().
  34. */
  35. function entity_test_i18n_entity_test_type_update($test_type) {
  36. // Account for name changes.
  37. if ($test_type->original->name != $test_type->name) {
  38. i18n_string_update_context("entity_test:entity_test_type:{$test_type->original->name}:*", "entity_test:entity_test_type:{$test_type->name}:*");
  39. }
  40. i18n_string_object_update('entity_test_type', $test_type);
  41. }
  42. /**
  43. * Implements hook_{entity_test_type}_delete().
  44. */
  45. function entity_test_i18n_entity_test_type_delete($test_type) {
  46. i18n_string_object_remove('entity_test_type', $test_type);
  47. }