summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEarl Miles2009-06-01 21:55:38 (GMT)
committer Earl Miles2009-06-01 21:55:38 (GMT)
commit3b8516e4593f7f7785602160f7171c3153701029 (patch)
tree6bf51e7af8d70b4e29db905b6faae291b9eb66b3
parentb2b5deb76c534323ff2b700ebbf87c261894a9e6 (diff)
#154865 by Zack Rosen, josh_k and KarenS: Allow user contact form as a field.
-rw-r--r--CHANGELOG.txt1
-rw-r--r--includes/handlers.inc2
-rw-r--r--modules/contact.views.inc33
-rw-r--r--modules/contact/views_handler_field_contact_link.inc50
4 files changed, 86 insertions, 0 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index c1476cc..5ec99a3 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -10,6 +10,7 @@ Views 3.x-dev
o #340701 by swentel: Restore allowing Views to set block caching mode.
o #347892 by dww: Allow <any> option in Boolean filters.
o #358314 by brmassa: Catch the exposed filter form so it doesn't process twice on a single view.
+ o #154865 by Zack Rosen, josh_k and KarenS: Allow user contact form as a field.
Views 2.x
Other Changes
diff --git a/includes/handlers.inc b/includes/handlers.inc
index 6bee442..a42918a 100644
--- a/includes/handlers.inc
+++ b/includes/handlers.inc
@@ -1453,3 +1453,5 @@ function translation_views_api() { return views_views_api(); }
function upload_views_api() { return views_views_api(); }
function user_views_api() { return views_views_api(); }
+
+function contact_views_api() { return views_views_api(); }
diff --git a/modules/contact.views.inc b/modules/contact.views.inc
new file mode 100644
index 0000000..30f301c
--- /dev/null
+++ b/modules/contact.views.inc
@@ -0,0 +1,33 @@
+<?php
+//$Id$
+/**
+ * @file
+ * Provide views data and handlers for contact.module
+ */
+
+function contact_views_data() {
+ $data['users']['contact'] = array(
+ 'field' => array(
+ 'title' => t('Link to contact page'),
+ 'help' => t('Provide a simple link to the user contact page.'),
+ 'handler' => 'views_handler_field_contact_link',
+ ),
+ );
+ return $data;
+}
+/**
+ * Implementation of hook_views_handlers() to register all of the basic handlers
+ * views uses.
+ */
+function contact_views_handlers() {
+ return array(
+ 'info' => array(
+ 'path' => drupal_get_path('module', 'views') . '/modules/contact',
+ ),
+ 'handlers' => array(
+ 'views_handler_field_contact_link' => array(
+ 'parent' => 'views_handler_field_user_link',
+ ),
+ ),
+ );
+}
diff --git a/modules/contact/views_handler_field_contact_link.inc b/modules/contact/views_handler_field_contact_link.inc
new file mode 100644
index 0000000..277f399
--- /dev/null
+++ b/modules/contact/views_handler_field_contact_link.inc
@@ -0,0 +1,50 @@
+<?php
+// $Id$
+/**
+ * A field that links to the user contact page, if access is permitted.
+ */
+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 render($values) {
+ global $user;
+ $uid = $values->{$this->aliases['uid']};
+ $account = user_load(array('uid' => $uid));
+
+ // Check access when we pull up the user account so we know
+ // if the user has made the contact page available.
+ if (! _contact_user_tab_access($account)) {
+ return;
+ }
+ if ($account !== FALSE && $account->contact && $user->uid > 0) {
+ 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)))));
+ }
+ }
+ }
+}
+