customer-riverside/web/modules/custom/riverside_pt/riverside_pt.module

155 lines
4.6 KiB
Text
Raw Permalink Normal View History

2026-05-13 13:55:52 -08:00
<?php
2026-05-13 14:26:33 -08:00
use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
function riverside_pt_page_attachments(array &$attachments): void {
$route = \Drupal::routeMatch()->getRouteName() ?? '';
if (!str_starts_with($route, 'riverside_pt.')) {
return;
}
2026-05-16 10:45:33 -08:00
$attachments['#attached']['library'][] = 'riverside_pt/app';
}
2026-05-14 20:23:54 -08:00
function riverside_pt_theme(): array {
return [
'riverside_pt_header' => [
'variables' => [
'site_name' => NULL,
'home_url' => NULL,
'menu_items' => [],
'current_path' => NULL,
],
],
2026-05-16 10:45:33 -08:00
'riverside_pt_home' => [
'variables' => [],
],
'riverside_pt_about' => [
'variables' => [],
],
'riverside_pt_service' => [
'variables' => [
'slug' => NULL,
'title' => NULL,
'description' => NULL,
'long_description' => NULL,
'what_to_expect' => NULL,
'benefits' => [],
],
],
'riverside_pt_contact' => [
'variables' => [],
],
2026-05-14 20:23:54 -08:00
];
}
function riverside_pt_page_top(array &$page_top): void {
$route = \Drupal::routeMatch()->getRouteName() ?? '';
if (!str_starts_with($route, 'riverside_pt.')) {
return;
}
2026-05-14 20:23:54 -08:00
$page_top['rpt_header'] = [
'#theme' => 'riverside_pt_header',
'#cache' => ['contexts' => ['url.path', 'route']],
2026-05-14 20:23:54 -08:00
];
}
function riverside_pt_preprocess_riverside_pt_header(array &$variables): void {
$variables['site_name'] = \Drupal::config('system.site')->get('name');
$variables['home_url'] = \Drupal\Core\Url::fromRoute('<front>')->toString();
$tree_service = \Drupal::service('menu.link_tree');
$params = new \Drupal\Core\Menu\MenuTreeParameters();
$params->setMaxDepth(1);
$tree = $tree_service->load('main', $params);
$tree = $tree_service->transform($tree, [
['callable' => 'menu.default_tree_manipulators:checkAccess'],
['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
]);
$seen = [];
$items = [];
foreach ($tree as $element) {
if (!$element->access->isAllowed()) {
continue;
}
$url = $element->link->getUrlObject()->toString();
if (in_array($url, $seen, TRUE)) {
continue;
}
$seen[] = $url;
$title = (string) $element->link->getTitle();
$items[] = [
'title' => $title,
'url' => $url,
2026-05-16 08:52:21 -08:00
'is_cta' => ($title === 'Book An Appointment' || $title === 'Contact'),
2026-05-14 20:23:54 -08:00
];
}
$variables['menu_items'] = $items;
$variables['current_path'] = \Drupal::request()->getPathInfo();
}
2026-05-13 13:55:52 -08:00
function riverside_pt_mail(string $key, array &$message, array $params): void {
$service_map = [
'diagnostic' => 'Diagnostic Assessment',
'sports' => 'Sports Rehabilitation',
'surgical' => 'Surgery Rehabilitation',
'neuro' => 'Neurological Therapy',
];
$service_label = $service_map[$params['service'] ?? ''] ?? 'Appointment';
if ($key === 'booking_request') {
$start = new \DateTime($params['start']);
$end = new \DateTime($params['end']);
$message['subject'] = 'Booking request — ' . $start->format('M j, Y g:i A');
$lines = [
'Name: ' . ($params['first_name'] ?? '') . ' ' . ($params['last_name'] ?? ''),
'Email: ' . ($params['email'] ?? ''),
'Service: ' . $service_label,
'Phone: ' . ($params['phone'] ?? ''),
'Slot: ' . $start->format('l, F j, Y') . ', ' . $start->format('g:i A') . '' . $end->format('g:i A'),
];
if (!empty($params['comments'])) {
$lines[] = 'Comments: ' . $params['comments'];
}
$message['body'][] = implode("\n", $lines);
2026-05-13 13:55:52 -08:00
return;
}
if ($key === 'booking_confirmation') {
$start = new \DateTime($params['start']);
$end = new \DateTime($params['end']);
2026-05-13 13:55:52 -08:00
$first = $params['first_name'] ?? 'Patient';
$message['subject'] = 'Your appointment is confirmed — ' . $start->format('M j, Y g:i A');
2026-05-13 14:26:33 -08:00
$lines = [
'Dear ' . $first . ',',
'',
'Your appointment is *confirmed* for:',
$start->format('l, F j, Y') . ', ' . $start->format('g:i A') . '' . $end->format('g:i A') . ' PST',
'',
'Service: ' . $service_label,
];
2026-05-13 14:26:33 -08:00
$full_name = trim(($params['first_name'] ?? '') . ' ' . ($params['last_name'] ?? ''));
if ($full_name) {
$lines[] = 'Name: ' . $full_name;
}
if (!empty($params['phone'])) {
$lines[] = 'Phone: ' . $params['phone'];
}
$lines[] = '';
$lines[] = 'We look forward to seeing you at Riverside Physical Therapy.';
$lines[] = 'If you need to cancel or reschedule, please contact us as soon as possible.';
$message['body'][] = implode("\n", $lines);
return;
}
2026-05-13 13:55:52 -08:00
}