i18n_contact.module 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * @file
  4. * Internationalization (i18n) submodule: Multilingual contact forms
  5. *
  6. * @author Jose A. Reyero, 2005
  7. */
  8. /**
  9. * Implements hook_menu().
  10. *
  11. * Add translate tab to contact config.
  12. */
  13. function i18n_contact_menu() {
  14. $items['admin/structure/contact/edit/%contact/edit'] = array(
  15. 'title' => 'Edit',
  16. 'type' => MENU_DEFAULT_LOCAL_TASK,
  17. 'weight' => -100,
  18. );
  19. return $items;
  20. }
  21. /**
  22. * Implements hook_form_FORM_ID_alter().
  23. */
  24. function i18n_contact_form_contact_category_delete_form_alter(&$form, &$form_state) {
  25. $form['#submit'][] = 'i18n_contact_form_contact_category_delete_form_submit';
  26. }
  27. /**
  28. * Remove strings for deleted categories.
  29. */
  30. function i18n_contact_form_contact_category_delete_form_submit(&$form, $form_state) {
  31. i18n_string_object_remove('contact_category', $form['contact']['#value']);
  32. }
  33. /**
  34. * Implements hook_form_FORM_ID_alter().
  35. */
  36. function i18n_contact_form_contact_category_edit_form_alter(&$form, &$form_state) {
  37. $form['actions']['translate'] = array(
  38. '#type' => 'submit',
  39. '#name' => 'save_translate',
  40. '#value' => t('Save and translate'),
  41. );
  42. $form['#submit'][] = 'i18n_contact_form_contact_category_edit_form_submit';
  43. }
  44. /**
  45. * Remove strings for edited/added categories.
  46. */
  47. function i18n_contact_form_contact_category_edit_form_submit($form, &$form_state) {
  48. $contact = $form_state['values'];
  49. i18n_string_object_update('contact_category', $contact);
  50. // If the save and translate button was clicked, redirect to the translate
  51. // tab instead of the block overview.
  52. if ($form_state['triggering_element']['#name'] == 'save_translate') {
  53. $form_state['redirect'] = 'admin/structure/contact/edit/' . $contact['cid'] . '/translate';
  54. }
  55. }
  56. /**
  57. * Implements hook_form_FORM_ID_alter().
  58. */
  59. function i18n_contact_form_contact_site_form_alter(&$form, &$form_state) {
  60. // Example of array translation. The placeholder '*' indicates the name part to be replace by the array keys
  61. if (isset($form['cid']['#options'])) {
  62. $form['cid']['#options'] = i18n_string_translate("contact:category:*:category", $form['cid']['#options'], array('sanitize' => FALSE));
  63. }
  64. }
  65. /**
  66. * Implements hook_mail_alter().
  67. */
  68. function i18n_contact_mail_alter(&$message) {
  69. if (in_array($message['id'], array('contact_page_mail', 'contact_page_copy', 'contact_page_autoreply'))) {
  70. // Alter the first part of the subject of emails going out if they need
  71. // translation.
  72. $contact = i18n_string_object_translate('contact_category', $message['params']['category'], array('langcode' => $message['language']->language));
  73. $message['subject'] = t(
  74. '[!category] !subject',
  75. array('!category' => $contact['category'], '!subject' => $message['params']['subject']),
  76. array('langcode' => $message['language']->language)
  77. );
  78. if ($message['id'] == 'contact_page_autoreply') {
  79. // Overwrite the whole message body. Maybe this is not entirely responsible
  80. // (it might overwrite other existing items altered in by others),
  81. // but unfortunately Drupal core cotact module does not make its item
  82. // identifiable easily.
  83. $message['body'] = array($contact['reply']);
  84. }
  85. }
  86. }