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

83 lines
2.0 KiB
Plaintext
Raw Normal View History

<?php
/**
* @file
* Contains opencase.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* 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_preprocess_page_title
*
* Modify the page title to include more information
*/
function opencase_preprocess_page_title(&$variables) {
$route_name = \Drupal::routeMatch()->getRouteName();
switch ($route_name) {
case 'entity.oc_case.canonical':
$case = \Drupal::routeMatch()->getParameter('oc_case');
$variables['title'] = $case->getName() . ": Case Details and Files";
break;
case 'view.cases.page_1':
$actor_id = \Drupal::routeMatch()->getParameter('actor_id');
$actor = \Drupal::entityTypeManager()->getStorage('oc_actor')->load($actor_id);
$variables['title'] = $actor->getName() . ": Cases";
break;
case 'view.activities.page_1':
$case_id = \Drupal::routeMatch()->getParameter('case_id');
$case = \Drupal::entityTypeManager()->getStorage('oc_case')->load($case_id);
$variables['title'] = $case->getName() . ": Activities";
break;
}
}
/**
* 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',
],
];
}