crm_core_contact.module in CRM Core 8
Same filename and directory in other branches
Provides default CRM Core Contact entities and the ability to create more.
File
modules/crm_core_contact/crm_core_contact.moduleView source
<?php
/**
* @file
* Provides default CRM Core Contact entities and the ability to create more.
*/
use Drupal\Core\Render\Element;
/**
* Implements hook_theme().
*/
function crm_core_contact_theme() {
return [
'crm_core_contact' => [
'render element' => 'elements',
'template' => 'crm-core-contact',
],
];
}
/**
* Process variables for CRM Core Contact.
*
* Default template: crm_core_contact.html.twig.
*
* @param array $variables
* An associative array containing:
* - crm_core_contact: The CRM Core Contact entity.
*/
function template_preprocess_crm_core_contact(array &$variables) {
$variables['view_mode'] = $variables['elements']['#view_mode'];
/** @var \Drupal\crm_core_contact\Entity\Contact $contact */
$contact = $variables['elements']['#crm_core_contact'];
$variables['crm_core_contact'] = $contact;
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
// Add classes based on the type of contact.
$variables['attributes']['class'][] = 'crm_core_contact';
$variables['attributes']['class'][] = 'crm_core_contact-' . $contact
->bundle();
}
/**
* Implements hook_theme_suggestions_HOOK().
*
* This function simply adds template suggestions for various
* contact types.
*/
function crm_core_contact_theme_suggestions_crm_core_contact(array $variables) {
$suggestions = [];
/** @var \Drupal\crm_core_contact\Entity\Contact $crm_core_contact */
$crm_core_contact = $variables['elements']['#crm_core_contact'];
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
// Add template suggestions.
$suggestions[] = 'crm_core_contact__' . $sanitized_view_mode;
$suggestions[] = 'crm_core_contact__' . $crm_core_contact
->bundle();
$suggestions[] = 'crm_core_contact__' . $crm_core_contact
->bundle() . '__' . $sanitized_view_mode;
$suggestions[] = 'crm_core_contact__' . $crm_core_contact
->id();
$suggestions[] = 'crm_core_contact__' . $crm_core_contact
->id() . '__' . $sanitized_view_mode;
return $suggestions;
}
/**
* Implements hook_mail().
*/
function crm_core_contact_mail($key, &$message, $params) {
$message['subject'] = $params['subject'];
$message['body'][] = $params['message'];
}
/**
* Implements hook_entity_dependencies().
*
* Adding contact activities and relationships as dependencies.
*/
function crm_core_contact_entity_dependencies($entity, $entity_type) {
$dependencies = [];
if ($entity_type == 'crm_core_contact') {
// Lets check activities.
if (module_exists('crm_core_activity')) {
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'crm_core_activity');
$query
->fieldCondition('field_activity_participants', 'target_id', $entity->contact_id);
$query
->fieldCondition('field_activity_participants', 'target_type', 'crm_core_contact');
$result = $query
->execute();
if (!empty($result['crm_core_activity'])) {
foreach (array_keys($result['crm_core_activity']) as $activity_id) {
$dependencies[] = [
'type' => 'crm_core_activity',
'id' => $activity_id,
];
}
}
}
// Lets check relations.
if (module_exists('relation')) {
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'relation');
$query
->fieldCondition('endpoints', 'entity_id', $entity->contact_id);
$result = $query
->execute();
if (!empty($result['relation'])) {
foreach (array_keys($result['relation']) as $rid) {
$dependencies[] = [
'type' => 'relation',
'id' => $rid,
];
}
}
}
}
return $dependencies;
}
Functions
Name | Description |
---|---|
crm_core_contact_entity_dependencies | Implements hook_entity_dependencies(). |
crm_core_contact_mail | Implements hook_mail(). |
crm_core_contact_theme | Implements hook_theme(). |
crm_core_contact_theme_suggestions_crm_core_contact | Implements hook_theme_suggestions_HOOK(). |
template_preprocess_crm_core_contact | Process variables for CRM Core Contact. |