commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / drupal / modules / views / civicrm / civicrm_handler_field_contact_link.inc
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | This file is a part of CiviCRM. |
7 | |
8 | CiviCRM is free software; you can copy, modify, and distribute it |
9 | under the terms of the GNU Affero General Public License |
10 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
11 | |
12 | CiviCRM is distributed in the hope that it will be useful, but |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
15 | See the GNU Affero General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU Affero General Public |
18 | License and the CiviCRM Licensing Exception along |
19 | with this program; if not, contact CiviCRM LLC |
20 | at info[AT]civicrm[DOT]org. If you have questions about the |
21 | GNU Affero General Public License or the licensing of CiviCRM, |
22 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
23 +--------------------------------------------------------------------+
24 */
25
26 /*
27 * Unchanged anonymous code contribution. No claim.
28 *
29 * civicrm_handler_field_contact_link.inc
30 * Display text data and has the option to link to it's related contact.
31 *
32 */
33 class civicrm_handler_field_contact_link extends views_handler_field {
34
35 /**
36 * Constructor to provide additional field to add.
37 */
38 function construct() {
39 parent::construct();
40 $this->additional_fields['id'] = 'id';
41 }
42
43 function option_definition() {
44 $options = parent::option_definition();
45 $options['link_to_civicrm_contact'] = array('default' => FALSE);
46 return $options;
47 }
48
49 /**
50 * Provide link to node option
51 */
52 function options_form(&$form, &$form_state) {
53 parent::options_form($form, $form_state);
54 $form['link_to_civicrm_contact'] = array(
55 '#title' => t('Link this field to its CiviCRM Contact'),
56 '#type' => 'checkbox',
57 '#default_value' => !empty($this->options['link_to_civicrm_contact']),
58 );
59 }
60
61 /**
62 * Render whatever the data is as a link to the node.
63 *
64 * Data should be made XSS safe prior to calling this function.
65 */
66 function render_link($data, $values) {
67 if (!empty($this->options['link_to_civicrm_contact']) && user_access('access CiviCRM') && $data !== NULL && $data !== '') {
68 return civicrm_views_href($data,
69 'civicrm/contact/view',
70 "reset=1&cid={$values->{$this->aliases['id']}}"
71 );
72 }
73 else {
74 return $data;
75 }
76 }
77
78 function render($values) {
79 return $this->render_link(check_plain($values->{$this->field_alias}), $values);
80 }
81 }
82