function crm_core_relationship_ui_field_formatter_view in CRM Core 8.2
Same name and namespace in other branches
- 8.3 modules/crm_core_relationship_ui/crm_core_relationship_ui.module \crm_core_relationship_ui_field_formatter_view()
- 8 modules/crm_core_relationship_ui/crm_core_relationship_ui.module \crm_core_relationship_ui_field_formatter_view()
- 7 modules/crm_core_relationship_ui/crm_core_relationship_ui.module \crm_core_relationship_ui_field_formatter_view()
Implements hook_field_formatter_view
File
- modules/
crm_core_relationship_ui/ crm_core_relationship_ui.module, line 231
Code
function crm_core_relationship_ui_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
switch ($display['type']) {
case 'contact_relationship_view':
// getting the contact id from the url
$current_contact_id = $display['views_view']->args[0];
$related_contact_id = $items[1]['entity_id'] == $current_contact_id ? $items[0]['entity_id'] : $items[1]['entity_id'];
$related_contact = Contact::load($related_contact_id);
$contact_label = entity_label('crm_core_contact', $related_contact);
$relation_type = RelationType::load($entity
->bundle());
$relationship_type = $items[1]['entity_id'] == $current_contact_id ? $relation_type
->reverseLabel() : $relation_type
->label();
$created = date('Y-m-d H:i:s', $entity->created);
$related_contact_uri = entity_uri('crm_core_contact', $related_contact);
$rows[] = array(
l($contact_label, $related_contact_uri['path'], $related_contact_uri['options']),
$relationship_type,
$created,
);
$headers = array(
'Related Contact',
'Relationship Type',
'Created',
);
return array(
'#theme' => 'table',
'#header' => $headers,
'#rows' => $rows,
);
break;
case 'contact_relationship':
// getting the contact id from the url
$current_contact_id = $display['views_view']->args[0];
if (isset($items[0]['entity_id']) && isset($items[1]['entity_id'])) {
$related_contact_id = $items[1]['entity_id'] == $current_contact_id ? $items[0]['entity_id'] : $items[1]['entity_id'];
$related_contact = Contact::load($related_contact_id);
$contact_label = entity_label('crm_core_contact', $related_contact);
$related_contact_uri = entity_uri('crm_core_contact', $related_contact);
return array(
array(
'#markup' => l($contact_label, $related_contact_uri['path']),
),
);
}
return array(
array(
'#markup' => '',
),
);
break;
case 'contact_relationship_human':
$current_contact_id = $display['views_view']->args[0];
$current_contact = Contact::load($current_contact_id);
$current_contact_label = entity_label('crm_core_contact', $current_contact);
$current_contact_uri = entity_uri('crm_core_contact', $current_contact);
$current_contact_link = l($current_contact_label, $current_contact_uri['path']);
$related_contact_id = $items[1]['entity_id'] == $current_contact_id ? $items[0]['entity_id'] : $items[1]['entity_id'];
$related_contact = Contact::load($related_contact_id);
$related_contact_label = entity_label('crm_core_contact', $related_contact);
$related_contact_uri = entity_uri('crm_core_contact', $related_contact);
$related_contact_link = l($related_contact_label, $related_contact_uri['path']);
$relationship_type = RelationType::load($entity
->bundle());
// Check if we need a reverse label.
$relation_label = '';
$relation_type = RelationType::load($entity
->bundle());
if ($relationship_type->directional && $items[1]['entity_id'] == $current_contact_id) {
$relation_label = strtolower($relation_type
->reverseLabel());
}
else {
$relation_label = strtolower($relation_type
->label());
}
return array(
array(
'#markup' => t('!current_contact is a @relation !related_contact', array(
'!current_contact' => $current_contact_link,
'@relation' => $relation_label,
'!related_contact' => $related_contact_link,
)),
),
);
break;
case 'contact_relationship_current':
$current_contact_id = $display['views_view']->args[0];
$current_contact = Contact::load($current_contact_id);
$current_contact_label = entity_label('crm_core_contact', $current_contact);
return array(
array(
'#markup' => t('@current_contact', array(
'@current_contact' => $current_contact_label,
)),
),
);
break;
}
}