Projet

Général

Profil

Paste
Télécharger (1,6 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / modules / contact / views_handler_field_contact_link.inc @ 76df55b7

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_handler_field_contact_link.
6
 */
7

    
8
/**
9
 * A field that links to the user contact page, if access is permitted.
10
 *
11
 * @ingroup views_field_handlers
12
 */
13
class views_handler_field_contact_link extends views_handler_field_user_link {
14

    
15
  function options_form(&$form, &$form_state) {
16
    $form['text']['#title'] = t('Link label');
17
    $form['text']['#required'] = TRUE;
18
    $form['text']['#default_value'] = empty($this->options['text']) ? t('contact') : $this->options['text'];
19
    parent::options_form($form, $form_state);
20
  }
21

    
22
  // An example of field level access control.
23
  // We must override the access method in the parent class, as that requires
24
  // the 'access user profiles' permission, which the contact form does not.
25
  function access() {
26
    return user_access('access user contact forms');
27
  }
28

    
29
  function render_link($data, $values) {
30
    global $user;
31
    $uid = $this->get_value($values, 'uid');
32

    
33
    if (empty($uid)) {
34
      return;
35
    }
36

    
37
    $account = user_load($uid);
38
    if (empty($account)) {
39
      return;
40
    }
41

    
42
    // Check access when we pull up the user account so we know
43
    // if the user has made the contact page available.
44
    $menu_item = menu_get_item("user/$uid/contact");
45
    if (!$menu_item['access'] || empty($account->data['contact'])) {
46
      return;
47
    }
48

    
49
    $this->options['alter']['make_link'] = TRUE;
50
    $this->options['alter']['path'] = 'user/' . $account->uid . '/contact';
51
    $this->options['alter']['attributes'] = array('title' => t('Contact %user', array('%user' => $account->name)));
52

    
53
    $text = $this->options['text'];
54

    
55
    return $text;
56
  }
57
}