Projet

Général

Profil

Paste
Télécharger (3,12 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / i18n / i18n_contact / i18n_contact.module @ 76df55b7

1
<?php
2
/**
3
 * @file
4
 * Internationalization (i18n) submodule: Multilingual contact forms
5
 *
6
 * @author Jose A. Reyero, 2005
7
 */
8

    
9
/**
10
 * Implements hook_menu().
11
 *
12
 * Add translate tab to contact config.
13
 */
14
function i18n_contact_menu() {
15
  $items['admin/structure/contact/edit/%contact/edit'] = array(
16
    'title' => 'Edit',
17
    'type' => MENU_DEFAULT_LOCAL_TASK,
18
    'weight' => -100,
19
  );
20
  return $items;
21
}
22

    
23
/**
24
 * Implements hook_form_FORM_ID_alter().
25
 */
26
function i18n_contact_form_contact_category_delete_form_alter(&$form, &$form_state) {
27
  $form['#submit'][] = 'i18n_contact_form_contact_category_delete_form_submit';
28
}
29

    
30
/**
31
 * Remove strings for deleted categories.
32
 */
33
function i18n_contact_form_contact_category_delete_form_submit(&$form, $form_state) {
34
  i18n_string_object_remove('contact_category', $form['contact']['#value']);
35
}
36

    
37
/**
38
 * Implements hook_form_FORM_ID_alter().
39
 */
40
function i18n_contact_form_contact_category_edit_form_alter(&$form, &$form_state) {
41
    $form['actions']['translate'] = array(
42
    '#type' => 'submit',
43
    '#name'   => 'save_translate',
44
    '#value' => t('Save and translate'),
45
  );
46
  $form['#submit'][] = 'i18n_contact_form_contact_category_edit_form_submit';
47
}
48

    
49
/**
50
 * Remove strings for edited/added categories.
51
 */
52
function i18n_contact_form_contact_category_edit_form_submit($form, &$form_state) {
53
  $contact = $form_state['values'];
54
  i18n_string_object_update('contact_category', $contact);
55
  // If the save and translate button was clicked, redirect to the translate
56
  // tab instead of the block overview.
57
  if ($form_state['triggering_element']['#name'] == 'save_translate') {
58
    $form_state['redirect'] = 'admin/structure/contact/edit/' . $contact['cid'] . '/translate';
59
  }
60
}
61

    
62
/**
63
 * Implements hook_form_FORM_ID_alter().
64
 */
65
function i18n_contact_form_contact_site_form_alter(&$form, &$form_state) {
66
  // Example of array translation. The placeholder '*' indicates the name part to be replace by the array keys
67
  if (isset($form['cid']['#options'])) {
68
    $form['cid']['#options'] = i18n_string_translate("contact:category:*:category", $form['cid']['#options'], array('sanitize' => FALSE));
69
  }
70
}
71

    
72
/**
73
 * Implements hook_mail_alter().
74
 */
75
function i18n_contact_mail_alter(&$message) {
76
  if (in_array($message['id'], array('contact_page_mail', 'contact_page_copy', 'contact_page_autoreply'))) {
77
    // Alter the first part of the subject of emails going out if they need
78
    // translation.
79
    $contact = i18n_string_object_translate('contact_category', $message['params']['category'], array('langcode' => $message['language']->language));
80
    $message['subject'] = t(
81
      '[!category] !subject',
82
      array('!category' => $contact['category'], '!subject' => $message['params']['subject']),
83
      array('langcode' => $message['language']->language)
84
    );
85

    
86
    if ($message['id'] == 'contact_page_autoreply') {
87
      // Overwrite the whole message body. Maybe this is not entirely responsible
88
      // (it might overwrite other existing items altered in by others),
89
      // but unfortunately Drupal core cotact module does not make its item
90
      // identifiable easily.
91
      $message['body'] = array($contact['reply']);
92
    }
93
  }
94
}