2018-04-04 10:59:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Contains zencrm_entities.module.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use Drupal\Core\Routing\RouteMatchInterface;
|
|
|
|
|
2018-04-05 21:02:55 +00:00
|
|
|
/**
|
2018-04-05 21:30:05 +00:00
|
|
|
* Implements hook_ENTITY_TYPE_presave().
|
|
|
|
* Computes the full_name field from first_name middle_names and last_name.
|
|
|
|
*/
|
2018-04-05 21:02:55 +00:00
|
|
|
function zencrm_entities_person_presave($entity) {
|
|
|
|
$first_name = $entity->first_name->getString();
|
|
|
|
$middle_names = $entity->middle_names->getString();
|
|
|
|
$last_name = $entity->last_name->getString();
|
|
|
|
if ($middle_names) {
|
|
|
|
$middle_names .= ' ';
|
|
|
|
}
|
|
|
|
$full_name = $first_name . ' ' . $middle_names . $last_name;
|
|
|
|
$entity->set('full_name', $full_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-06 13:34:03 +00:00
|
|
|
/**
|
|
|
|
* Implements hook_ENTITY_TYPE_presave().
|
|
|
|
* Computes the name field from the full name of the referenced person
|
2018-04-11 10:18:27 +00:00
|
|
|
* plus the hat type.
|
2018-04-06 13:34:03 +00:00
|
|
|
*/
|
2018-04-11 10:18:27 +00:00
|
|
|
function zencrm_entities_hat_presave($entity) {
|
2018-04-06 13:34:03 +00:00
|
|
|
$person_id = $entity->person->first()->getValue()['target_id'];
|
|
|
|
$person = \Drupal\zencrm_entities\Entity\Person::load($person_id);
|
|
|
|
$full_name = $person->full_name->getString();
|
|
|
|
$bundle_name = $entity->type->entity->label();
|
|
|
|
$entity->set('name', $full_name . ' - ' . $bundle_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-04 10:59:01 +00:00
|
|
|
/**
|
|
|
|
* Implements hook_help().
|
|
|
|
*/
|
|
|
|
function zencrm_entities_help($route_name, RouteMatchInterface $route_match) {
|
|
|
|
switch ($route_name) {
|
|
|
|
// Main module help for the zencrm_entities module.
|
|
|
|
case 'help.page.zencrm_entities':
|
|
|
|
$output = '';
|
|
|
|
$output .= '<h3>' . t('About') . '</h3>';
|
|
|
|
$output .= '<p>' . t('Zen CRM Entities') . '</p>';
|
|
|
|
return $output;
|
|
|
|
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_theme().
|
|
|
|
*/
|
|
|
|
function zencrm_entities_theme() {
|
2018-04-05 18:05:00 +00:00
|
|
|
$theme = [];
|
|
|
|
$theme['zencrm_entities'] = [
|
|
|
|
'render element' => 'children',
|
2018-04-04 10:59:01 +00:00
|
|
|
];
|
2018-04-11 10:18:27 +00:00
|
|
|
$theme['hat'] = [
|
2018-04-05 18:05:00 +00:00
|
|
|
'render element' => 'elements',
|
2018-04-11 10:18:27 +00:00
|
|
|
'file' => 'hat.page.inc',
|
|
|
|
'template' => 'hat',
|
2018-04-05 18:05:00 +00:00
|
|
|
];
|
2018-04-11 10:18:27 +00:00
|
|
|
$theme['hat_content_add_list'] = [
|
2018-04-05 18:05:00 +00:00
|
|
|
'render element' => 'content',
|
|
|
|
'variables' => ['content' => NULL],
|
2018-04-11 10:18:27 +00:00
|
|
|
'file' => 'hat.page.inc',
|
2018-04-05 18:05:00 +00:00
|
|
|
];
|
2018-04-12 13:32:24 +00:00
|
|
|
$theme['case_entity'] = [
|
|
|
|
'render element' => 'elements',
|
|
|
|
'file' => 'case_entity.page.inc',
|
|
|
|
'template' => 'case_entity',
|
|
|
|
];
|
|
|
|
$theme['case_entity_content_add_list'] = [
|
|
|
|
'render element' => 'content',
|
|
|
|
'variables' => ['content' => NULL],
|
|
|
|
'file' => 'case_entity.page.inc',
|
|
|
|
];
|
2018-04-14 10:26:09 +00:00
|
|
|
$theme['activity'] = [
|
|
|
|
'render element' => 'elements',
|
|
|
|
'file' => 'activity.page.inc',
|
|
|
|
'template' => 'activity',
|
|
|
|
];
|
|
|
|
$theme['activity_content_add_list'] = [
|
|
|
|
'render element' => 'content',
|
|
|
|
'variables' => ['content' => NULL],
|
|
|
|
'file' => 'activity.page.inc',
|
|
|
|
];
|
2018-04-05 18:05:00 +00:00
|
|
|
return $theme;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_theme_suggestions_HOOK().
|
|
|
|
*/
|
2018-04-11 10:18:27 +00:00
|
|
|
function zencrm_entities_theme_suggestions_hat(array $variables) {
|
2018-04-05 18:05:00 +00:00
|
|
|
$suggestions = [];
|
2018-04-11 10:18:27 +00:00
|
|
|
$entity = $variables['elements']['#hat'];
|
2018-04-05 18:05:00 +00:00
|
|
|
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
|
|
|
|
|
2018-04-11 10:18:27 +00:00
|
|
|
$suggestions[] = 'hat__' . $sanitized_view_mode;
|
|
|
|
$suggestions[] = 'hat__' . $entity->bundle();
|
|
|
|
$suggestions[] = 'hat__' . $entity->bundle() . '__' . $sanitized_view_mode;
|
|
|
|
$suggestions[] = 'hat__' . $entity->id();
|
|
|
|
$suggestions[] = 'hat__' . $entity->id() . '__' . $sanitized_view_mode;
|
2018-04-05 18:05:00 +00:00
|
|
|
return $suggestions;
|
2018-04-04 10:59:01 +00:00
|
|
|
}
|
2018-04-12 13:32:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_theme_suggestions_HOOK().
|
|
|
|
*/
|
|
|
|
function zencrm_entities_theme_suggestions_case_entity(array $variables) {
|
|
|
|
$suggestions = [];
|
|
|
|
$entity = $variables['elements']['#case_entity'];
|
|
|
|
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
|
|
|
|
|
|
|
|
$suggestions[] = 'case_entity__' . $sanitized_view_mode;
|
|
|
|
$suggestions[] = 'case_entity__' . $entity->bundle();
|
|
|
|
$suggestions[] = 'case_entity__' . $entity->bundle() . '__' . $sanitized_view_mode;
|
|
|
|
$suggestions[] = 'case_entity__' . $entity->id();
|
|
|
|
$suggestions[] = 'case_entity__' . $entity->id() . '__' . $sanitized_view_mode;
|
|
|
|
return $suggestions;
|
|
|
|
}
|
2018-04-14 10:26:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_theme_suggestions_HOOK().
|
|
|
|
*/
|
|
|
|
function zencrm_entities_theme_suggestions_activity(array $variables) {
|
|
|
|
$suggestions = [];
|
|
|
|
$entity = $variables['elements']['#activity'];
|
|
|
|
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
|
|
|
|
|
|
|
|
$suggestions[] = 'activity__' . $sanitized_view_mode;
|
|
|
|
$suggestions[] = 'activity__' . $entity->bundle();
|
|
|
|
$suggestions[] = 'activity__' . $entity->bundle() . '__' . $sanitized_view_mode;
|
|
|
|
$suggestions[] = 'activity__' . $entity->id();
|
|
|
|
$suggestions[] = 'activity__' . $entity->id() . '__' . $sanitized_view_mode;
|
|
|
|
return $suggestions;
|
|
|
|
}
|