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
|
/**
|
16
|
* {@inheritdoc}
|
17
|
*/
|
18
|
public function options_form(&$form, &$form_state) {
|
19
|
$form['text']['#title'] = t('Link label');
|
20
|
$form['text']['#required'] = TRUE;
|
21
|
$form['text']['#default_value'] = empty($this->options['text']) ? t('contact') : $this->options['text'];
|
22
|
parent::options_form($form, $form_state);
|
23
|
}
|
24
|
|
25
|
/**
|
26
|
* An example of field level access control.
|
27
|
*
|
28
|
* We must override the access method in the parent class, as that requires
|
29
|
* the 'access user profiles' permission, which the contact form does not.
|
30
|
*/
|
31
|
public function access() {
|
32
|
return user_access('access user contact forms');
|
33
|
}
|
34
|
|
35
|
/**
|
36
|
* {@inheritdoc}
|
37
|
*/
|
38
|
public function render_link($data, $values) {
|
39
|
global $user;
|
40
|
$uid = $this->get_value($values, 'uid');
|
41
|
|
42
|
if (empty($uid)) {
|
43
|
return;
|
44
|
}
|
45
|
|
46
|
$account = user_load($uid);
|
47
|
if (empty($account)) {
|
48
|
return;
|
49
|
}
|
50
|
|
51
|
// Check access when we pull up the user account so we know
|
52
|
// if the user has made the contact page available.
|
53
|
$menu_item = menu_get_item("user/$uid/contact");
|
54
|
if (!$menu_item['access'] || empty($account->data['contact'])) {
|
55
|
return;
|
56
|
}
|
57
|
|
58
|
$this->options['alter']['make_link'] = TRUE;
|
59
|
$this->options['alter']['path'] = 'user/' . $account->uid . '/contact';
|
60
|
$this->options['alter']['attributes'] = array('title' => t('Contact %user', array('%user' => $account->name)));
|
61
|
|
62
|
$text = $this->options['text'];
|
63
|
|
64
|
return $text;
|
65
|
}
|
66
|
|
67
|
}
|