views_handler_field_contact_link.inc in Views (for Drupal 7) 6.2
File
modules/contact/views_handler_field_contact_link.inc
View source
<?php
class views_handler_field_contact_link extends views_handler_field_user_link {
function option_definition() {
$options = parent::option_definition();
$options['link_display'] = array(
'default' => 'link',
'translatable' => FALSE,
);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['link_display'] = array(
'#title' => t('Type of link'),
'#default_value' => $this->options['link_display'],
'#type' => 'select',
'#options' => array(
'link' => t('Link'),
'icon' => t('Icon'),
),
);
$form['text']['#title'] = t('Link label');
$form['text']['#required'] = TRUE;
$form['text']['#default_value'] = empty($this->options['text']) ? t('contact') : $this->options['text'];
}
function access() {
global $user;
if (empty($user->uid)) {
return FALSE;
}
return TRUE;
}
function render($values) {
global $user;
$uid = $values->{$this->aliases['uid']};
if (empty($uid)) {
return;
}
$account = user_load($uid);
if (empty($account)) {
return;
}
$menu_item = menu_get_item("user/{$uid}/contact");
if (!$menu_item['access'] || empty($account->contact)) {
return;
}
if ($this->options['link_display'] == 'icon') {
return l(theme('image', 'misc/forum-new.png'), 'user/' . $account->uid . '/contact', array(
'html' => TRUE,
'attributes' => array(
'title' => t('Contact %user', array(
'%user' => $account->name,
)),
),
));
}
else {
return l($this->options['text'], 'user/' . $account->uid . '/contact', array(
'attributes' => array(
'title' => t('Contact %user', array(
'%user' => $account->name,
)),
),
));
}
}
}