Commit 87e63bfd authored by RoSk0's avatar RoSk0

Fixed contact type field handler link comment and added ability to display machine readable name.

parent ead0b0af
......@@ -5,7 +5,6 @@
* Export CRM Core Contact to views.
*/
/**
* Implements hook_views_data().
*/
......@@ -40,7 +39,7 @@ function crm_core_contact_views_data() {
$data['crm_core_contact']['type'] = array(
'title' => t('Contact Type'),
'help' => t('The human-readable name of the type of contact.'),
'help' => t('The human-readable(or machine) name of the type of contact.'),
'field' => array(
'handler' => 'crm_core_contact_handler_field_contact_type',
'click sortable' => TRUE,
......@@ -58,16 +57,16 @@ function crm_core_contact_views_data() {
);
// Expose the creator uid.
// $data['crm_core_contact']['uid'] = array(
// 'title' => t('Creator'),
// 'help' => t('Relate a contact to the user who created it.'),
// 'relationship' => array(
// 'handler' => 'views_handler_relationship',
// 'base' => 'users',
// 'field' => 'uid',
// 'label' => t('Contact creator'),
// ),
// );
// $data['crm_core_contact']['uid'] = array(
// 'title' => t('Creator'),
// 'help' => t('Relate a contact to the user who created it.'),
// 'relationship' => array(
// 'handler' => 'views_handler_relationship',
// 'base' => 'users',
// 'field' => 'uid',
// 'label' => t('Contact creator'),
// ),
// );
// Expose the created and changed timestamps.
$data['crm_core_contact']['created'] = array(
......@@ -110,14 +109,14 @@ function crm_core_contact_views_data() {
'help' => t('CRM Contact Types'),
);
// contact type table join for filtering purposes
// Contact type table join for filtering purposes.
$data['crm_core_contact_type']['table']['join']['crm_core_contact'] = array(
'left_field' => 'type',
'field' => 'type',
'left_field' => 'type',
'field' => 'type',
);
$data['crm_core_contact_type']['disabled'] = array(
'title' => t('Disabled contact type'),
'title' => t('Disabled contact type'),
'help' => t('If the contact type is disabled, mainly for filtering purposes'),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
......@@ -130,7 +129,6 @@ function crm_core_contact_views_data() {
),
);
$data['crm_core_contact_revision']['table']['group'] = t('CRM Contacts Revisions');
$data['crm_core_contact_revision']['table']['base'] = array(
......@@ -157,13 +155,13 @@ function crm_core_contact_views_data() {
),
);
$data['crm_core_contact_revision']['revert_link'] = array(
'field' => array(
'title' => t('Revision Link'),
'help' => t('Provide a simple link to revert the contact'),
'handler' => 'crm_core_contact_handler_field_contact_revert',
),
);
$data['crm_core_contact_revision']['revert_link'] = array(
'field' => array(
'title' => t('Revision Link'),
'help' => t('Provide a simple link to revert the contact'),
'handler' => 'crm_core_contact_handler_field_contact_revert',
),
);
$data['crm_core_contact_revision']['contact_id'] = array(
'title' => t('Contact ID'),
......@@ -193,13 +191,12 @@ function crm_core_contact_views_data() {
),
);
$data['crm_core_contact_revision']['table']['join'] = array(
'crm_core_contact' => array(
'left_field' => 'contact_id',
'field' => 'contact_id',
'extra' => 'crm_core_contact.vid = crm_core_contact_revision.vid',
// Can use AND or OR, not really needed here since it defaults to AND
'extra' => 'crm_core_contact.vid = crm_core_contact_revision.vid',
// Can use AND or OR, not really needed here since it defaults to AND.
'extra type' => 'AND',
),
);
......@@ -219,7 +216,6 @@ function crm_core_contact_views_data() {
),
);
// Expose the created and changed timestamps.
$data['crm_core_contact_revision']['created'] = array(
'title' => t('Created date'),
......@@ -254,12 +250,11 @@ function crm_core_contact_views_data() {
return $data;
}
/**
* Implements hook_views_data_alter().
*/
function crm_core_contact_views_data_alter(&$data) {
// Integration with Drupal search index
// Integration with Drupal search index.
$data['search_index']['table']['join']['crm_core_contact'] = array(
'left_field' => 'contact_id ',
'field' => 'sid',
......
<?php
/**
* @file
* Field handler to provide simple renderer that allows linking to a contact.
*/
/*
* Field handler to translate a contact type into its readable form.
/**
* Handler class.
*/
class crm_core_contact_handler_field_contact_type extends crm_core_contact_handler_field_contact {
class crm_core_contact_handler_field_contact_type extends views_handler_field {
/**
* Options definitions.
*/
function option_definition() {
$options = parent::option_definition();
$options['link_to_contact_type'] = array('default' => FALSE);
$options['machine_name'] = array('default' => FALSE);
return $options;
}
/**
* Options form builder.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
// Provide the link to contact type page.
$form['link_to_contact_type'] = array(
'#title' => t('Link this field to the contact type administrative page.'),
'#description' => t('This will override any other link you have set.'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_to_contact_type']),
);
// Display contact type as machine readable name.
$form['machine_name'] = array(
'#title' => t('Display contact type as machine readable name?'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['machine_name']),
);
}
/**
* Render callback.
*/
function render($values) {
$value = crm_core_contact_type_get_name($values->{$this->field_alias});
return $this->render_link((check_plain($value)), $values);
if ($this->options['link_to_contact_type']) {
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = 'admin/structure/crm-core/contact-types/manage/' . $values->{$this->field_alias};
}
$type = $this->options['machine_name'] ? $values->{$this->field_alias} : crm_core_contact_type_get_name($values->{$this->field_alias});
return check_plain($type);
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment