rules_link_i18n.module 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * @file
  4. * Rules link i18n integration module via entity API i18n support.
  5. *
  6. * @see EntityDefaultI18nController
  7. */
  8. /**
  9. * Implements hook_entity_info_alter().
  10. */
  11. function rules_link_i18n_entity_info_alter(&$info) {
  12. // Enable i18n support via the entity API.
  13. $info['rules_link']['i18n controller class'] = 'RulesLinkI18nController';
  14. }
  15. /**
  16. * Customized i18n string integration controller.
  17. */
  18. class RulesLinkI18nController extends EntityDefaultI18nStringController {
  19. /**
  20. * Overriddes EntityDefaultI18nStringController::hook_object_info() to include a custom object wrapper.
  21. */
  22. public function hook_object_info() {
  23. $info = parent::hook_object_info();
  24. $info['rules_link']['class'] = 'RulesLinkI18nStringObjectWrapper';
  25. return $info;
  26. }
  27. /**
  28. * Overrides EntityDefaultI18nStringController::translatableProperties() to define our custom ones.
  29. */
  30. protected function translatableProperties() {
  31. $properties = array();
  32. $properties['text'] = t('Link text');
  33. $properties['confirm_question'] = t('Confirm question');
  34. $properties['confirm_description'] = t('Confirm description');
  35. return $properties;
  36. }
  37. }
  38. /**
  39. * Custom i18n object wrapper.
  40. */
  41. class RulesLinkI18nStringObjectWrapper extends i18n_string_object_wrapper {
  42. /**
  43. * Overrides i18n_string_object_wrapper::get_field() to read properties from the settings array.
  44. */
  45. public function get_field($field, $default = NULL) {
  46. return isset($this->object->settings[$field]) ? $this->object->settings[$field] : parent::get_field($field, $default);
  47. }
  48. }
  49. /**
  50. * Implements hook_rules_link_insert().
  51. */
  52. function rules_link_i18n_rules_link_insert($rules_link) {
  53. i18n_string_object_update('rules_link', $rules_link);
  54. }
  55. /**
  56. * Implements hook_rules_link_update().
  57. */
  58. function rules_link_i18n_rules_link_update($rules_link) {
  59. // Account for name changes.
  60. if ($rules_link->original->name != $rules_link->name) {
  61. i18n_string_update_context("rules_link:rules_link:{$rules_link->original->name}:*", "rules_link:rules_link:{$rules_link->name}:*");
  62. }
  63. i18n_string_object_update('rules_link', $rules_link);
  64. }
  65. /**
  66. * Implements hook_rules_link_delete().
  67. */
  68. function rules_link_i18n_rules_link_delete($rules_link) {
  69. i18n_string_object_remove('rules_link', $rules_link);
  70. }