2018-04-29 07:22:16 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Contains opencase.module.
|
|
|
|
*/
|
|
|
|
|
2022-05-16 19:18:49 +00:00
|
|
|
use Drupal\Core\Render\Element;
|
2018-07-18 10:06:22 +00:00
|
|
|
use Drupal\Core\Access\AccessResult;
|
2022-05-18 12:40:03 +00:00
|
|
|
use Drupal\opencase_cases\Entity\OCCase;
|
2022-05-16 19:18:49 +00:00
|
|
|
use Drupal\Core\Routing\RouteMatchInterface;
|
2022-05-18 12:27:14 +00:00
|
|
|
use Drupal\opencase_cases\Entity\OCCaseProvision;
|
2018-04-29 07:22:16 +00:00
|
|
|
|
2020-03-01 09:42:06 +00:00
|
|
|
/**
|
|
|
|
* Implements hook_element_info_alter().
|
|
|
|
*/
|
|
|
|
function opencase_element_info_alter(array &$types) {
|
|
|
|
$types['datetime']['#process'][] = 'opencase_process_element';
|
|
|
|
}
|
|
|
|
|
2022-05-16 19:18:49 +00:00
|
|
|
function _template_preprocess_entity(&$variables) {
|
|
|
|
foreach (Element::children($variables['elements']) as $key) {
|
|
|
|
if (is_extra_field($variables['elements'][$key])) {
|
|
|
|
$variables['extra_fields'][$key] = $variables['elements'][$key];
|
|
|
|
} else {
|
|
|
|
$variables['normal_fields'][$key] = $variables['elements'][$key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function is_extra_field($element){
|
|
|
|
return array_key_exists('#field', $element);
|
|
|
|
}
|
2022-05-12 08:03:11 +00:00
|
|
|
|
2020-03-01 09:42:06 +00:00
|
|
|
/**
|
|
|
|
* Element process callback for datetime fields. Removes the seconds part.
|
|
|
|
*/
|
|
|
|
function opencase_process_element($element) {
|
|
|
|
if ($element['#date_time_element'] !== 'none') {
|
|
|
|
$element['#date_time_format'] = 'H:i';
|
|
|
|
}
|
|
|
|
if (!empty($element['time']['#value'])) {
|
|
|
|
$parts = explode(':', $element['time']['#value']);
|
|
|
|
$parts = array_splice($parts, 0, 2);
|
|
|
|
$element['time']['#value'] = implode(':', $parts);
|
|
|
|
}
|
|
|
|
// Remove seconds in browsers that support HTML5 type=date.
|
|
|
|
$element['time']['#attributes']['step'] = 60;
|
|
|
|
return $element;
|
|
|
|
}
|
2022-05-18 12:27:14 +00:00
|
|
|
function opencase_oc_case_provision_insert(OCCaseProvision $case_provision): void {
|
|
|
|
$case_provision->oc_provider->entity->calculateTotalCases();
|
|
|
|
}
|
|
|
|
function opencase_oc_case_provision_delete(OCCaseProvision $case_provision): void {
|
|
|
|
$case_provision->oc_provider->entity->calculateTotalCases();
|
|
|
|
}
|
|
|
|
function opencase_oc_case_provision_update(OCCaseProvision $case_provision): void {
|
|
|
|
$case_provision->oc_provider->entity->calculateTotalCases();
|
|
|
|
$case_provision->original->oc_provider->entity->calculateTotalCases();
|
|
|
|
}
|
2018-05-07 17:20:09 +00:00
|
|
|
|
2022-05-18 12:40:03 +00:00
|
|
|
function opencase_oc_case_delete(OCCase $case): void {
|
|
|
|
$case->deleteCaseProvisions();
|
|
|
|
}
|
|
|
|
|
2018-05-07 16:54:08 +00:00
|
|
|
/**
|
|
|
|
* Implements hook_page_attachments
|
|
|
|
*
|
|
|
|
* Add the opencase library to every page
|
|
|
|
*/
|
|
|
|
function opencase_page_attachments(array &$page) {
|
|
|
|
$page['#attached']['library'][] = 'opencase/opencase-lib';
|
|
|
|
}
|
|
|
|
|
2018-05-07 16:31:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_link_alter
|
|
|
|
*
|
|
|
|
* Makes menu items that are external links open in new tab.
|
|
|
|
*/
|
|
|
|
function opencase_link_alter(&$variables) {
|
|
|
|
if ($variables['url']->isExternal()) {
|
|
|
|
$variables['options']['attributes'] = ['target' => '_blank'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-29 07:22:16 +00:00
|
|
|
/**
|
|
|
|
* Implements hook_help().
|
|
|
|
*/
|
|
|
|
function opencase_help($route_name, RouteMatchInterface $route_match) {
|
|
|
|
switch ($route_name) {
|
|
|
|
// Main module help for the opencase module.
|
|
|
|
case 'help.page.opencase':
|
|
|
|
$output = '';
|
|
|
|
$output .= '<h3>' . t('About') . '</h3>';
|
|
|
|
$output .= '<p>' . t('Simple Case Management') . '</p>';
|
|
|
|
return $output;
|
|
|
|
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_theme().
|
|
|
|
*/
|
|
|
|
function opencase_theme() {
|
|
|
|
return [
|
|
|
|
'opencase' => [
|
|
|
|
'render element' => 'children',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2018-05-28 14:21:56 +00:00
|
|
|
|
2018-07-05 12:05:50 +00:00
|
|
|
/**
|
|
|
|
* Implements hook_uninstall().
|
|
|
|
* Removes configs.
|
|
|
|
*/
|
|
|
|
function opencase_uninstall() {
|
|
|
|
$configs = [
|
2019-11-11 11:14:57 +00:00
|
|
|
'block.block.opencase',
|
|
|
|
'system.menu.opencase',
|
2021-01-28 11:54:07 +00:00
|
|
|
'views.view.contact_details_changes',
|
2021-02-18 16:46:59 +00:00
|
|
|
'views.view.equal_opps_records',
|
2021-02-20 15:09:58 +00:00
|
|
|
'block.block.exposedformequal_opps_recordspage_1',
|
2018-07-05 12:05:50 +00:00
|
|
|
];
|
|
|
|
foreach($configs as $config) {
|
|
|
|
Drupal::configFactory()->getEditable($config)->delete();
|
|
|
|
}
|
|
|
|
}
|
2018-07-09 18:38:48 +00:00
|
|
|
|
|
|
|
function opencase_views_pre_render($view) {
|
2021-09-13 13:15:02 +00:00
|
|
|
if (!empty($view->result)) {
|
|
|
|
foreach ($view->result as $key => $result) {
|
|
|
|
if (empty($result->_entity)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$access = \Drupal::entityTypeManager()
|
|
|
|
->getAccessControlHandler($result->_entity->getEntityTypeId())
|
|
|
|
->access($result->_entity, 'view', NULL, TRUE);
|
|
|
|
|
|
|
|
if (!$access->isAllowed()) {
|
|
|
|
unset($view->result[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-09 18:38:48 +00:00
|
|
|
if (empty($view->result) && empty($view->exposed_input)) {
|
|
|
|
$view->exposed_widgets = NULL;
|
|
|
|
}
|
|
|
|
}
|
2018-07-18 10:06:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
function opencase_entity_field_access($operation, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $account, $items = NULL) {
|
|
|
|
if ($field_definition->getName() == 'field_linked_opencase_actor'
|
|
|
|
&& $operation == 'edit'
|
|
|
|
&& !$account->hasPermission('administer users')) {
|
|
|
|
return AccessResult::forbidden();
|
|
|
|
}
|
|
|
|
return AccessResult::neutral();
|
|
|
|
}
|
2018-07-18 20:15:45 +00:00
|
|
|
|
2022-05-13 12:21:13 +00:00
|
|
|
/*
|
|
|
|
Implementation of hook_relevant_activity_type_ids which is a custom hook invoked in the AddActivity block.
|
|
|
|
*/
|
|
|
|
function opencase_relevant_activity_type_ids($actorTypeID) {
|
|
|
|
switch ($actorTypeID) {
|
|
|
|
case 'volunteer':
|
|
|
|
return ['email', 'phone_call', 'supervision'];
|
|
|
|
case 'client':
|
|
|
|
return ['email', 'lete', 'phone_call', 'case_note', 'destitution_funds_provided', 'research', 'application'];
|
|
|
|
case 'staff_member':
|
|
|
|
return ['application', 'interview'];
|
|
|
|
}
|
|
|
|
}
|
2018-07-18 20:15:45 +00:00
|
|
|
|
2021-07-20 12:48:50 +00:00
|
|
|
/**
|
|
|
|
* Implementation of hook_form_alter()
|
|
|
|
* Changes what page is redirected to after adding or deleting linked organisation
|
|
|
|
*/
|
|
|
|
function opencase_form_alter(&$form, &$form_state, $form_id) {
|
|
|
|
if (preg_match('/oc_organisation_relation_.*_delete_form/', $form_id) or (preg_match('/oc_organisation_relation_.*_add_form/', $form_id))) {
|
|
|
|
$form['actions']['submit']['#submit'][] = '_opencase_organisation_relation_redirect';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function _opencase_organisation_relation_redirect($form, &$form_state) {
|
|
|
|
$organisation_id = \Drupal::request()->query->get('organisation_id');
|
|
|
|
$form_state->setRedirect('entity.oc_organisation.canonical', ['oc_organisation' => $organisation_id]);
|
|
|
|
}
|