This repository has been archived on 2022-07-12. You can view files and clone it, but cannot push or open issues or pull requests.
opencase/opencase.module

117 lines
2.7 KiB
Plaintext

<?php
/**
* @file
* Contains opencase.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Access\AccessResult;
/**
* 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;
}
/**
* Implements hook_page_attachments
*
* Add the opencase library to every page
*/
function opencase_page_attachments(array &$page) {
$page['#attached']['library'][] = 'opencase/opencase-lib';
}
/**
* 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'];
}
}
/**
* 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',
],
];
}
/**
* Implements hook_uninstall().
* Removes configs.
*/
function opencase_uninstall() {
$configs = [
'block.block.opencase',
'system.menu.opencase',
'views.view.contact_details_changes',
'views.view.equal_opps_records',
'block.block.exposedformequal_opps_recordspage_1',
];
foreach($configs as $config) {
Drupal::configFactory()->getEditable($config)->delete();
}
}
function opencase_views_pre_render($view) {
if (empty($view->result) && empty($view->exposed_input)) {
$view->exposed_widgets = NULL;
}
}
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();
}