2018-04-29 07:22:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Contains opencase.module.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use Drupal\Core\Routing\RouteMatchInterface;
|
2018-07-18 10:06:22 +00:00
|
|
|
use Drupal\Core\Access\AccessResult;
|
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';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2018-05-07 17:20:09 +00:00
|
|
|
|
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) {
|
|
|
|
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
|
|
|
|
|
|
|
|