From 8a026f094943256e41c999fd414b396cc3d2f99c Mon Sep 17 00:00:00 2001
From: Tim Plunkett <git@plnktt.com>
Date: Thu, 24 Mar 2011 14:39:43 -0400
Subject: [PATCH] Issue #872354 by tim.plunkett: Use new permission for Views field access check.

---
 contact.module                         |   10 ++++++++
 contact.views.inc                      |   36 ++++++++++++++++++++++++++++++++
 contact_handler_field_contact_link.inc |   15 +++++++++++++
 3 files changed, 61 insertions(+), 0 deletions(-)
 create mode 100644 contact.views.inc
 create mode 100644 contact_handler_field_contact_link.inc

diff --git a/contact.module b/contact.module
index 6949ae2..079d16c 100644
--- a/contact.module
+++ b/contact.module
@@ -276,3 +276,13 @@ function contact_mollom_form_info_alter(&$form_info) {
 function _contact_user_tab_access(stdClass $account) {
   return _contact_personal_tab_access($account);
 }
+
+/**
+ * Implements hook_views_api().
+ */
+function contact_views_api() {
+  return array(
+    'api' => 2,
+    'path' => drupal_get_path('module', 'contact'),
+  );
+}
diff --git a/contact.views.inc b/contact.views.inc
new file mode 100644
index 0000000..2a27dca
--- /dev/null
+++ b/contact.views.inc
@@ -0,0 +1,36 @@
+<?php
+
+/**
+ * @file
+ * Declare Views handlers.
+
+/**
+ * Implements hook_views_data().
+ */
+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' => 'contact_handler_field_contact_link',
+    ),
+  );
+  return $data;
+}
+
+/**
+ * Implements hook_views_handlers().
+ */
+function contact_views_handlers() {
+  return array(
+    'handlers' => array(
+      'views_handler_field_contact_link' => array(
+        'parent' => 'views_handler_field_user_link',
+        'path' => drupal_get_path('module', 'views') . '/modules/contact',
+      ),
+      'contact_handler_field_contact_link' => array(
+        'parent' => 'views_handler_field_contact_link',
+      ),
+    ),
+  );
+}
diff --git a/contact_handler_field_contact_link.inc b/contact_handler_field_contact_link.inc
new file mode 100644
index 0000000..e957ef1
--- /dev/null
+++ b/contact_handler_field_contact_link.inc
@@ -0,0 +1,15 @@
+<?php
+
+/**
+ * @file
+ * Override access of core contact link field.
+ */
+/**
+ * A field that links to the user contact page, if access is permitted.
+ */
+class contact_handler_field_contact_link extends views_handler_field_contact_link {
+  // Views isn't aware of the new user contact permission.
+  function access() {
+    return user_access('access user contact forms');
+  }
+}
-- 
1.7.0.4

