customer-riverside/web/modules/custom/riverside_pt/riverside_pt.module
Philip Peterson 0d35dda628 Fix palette swatches, login styling, and login redirect
- PaletteController: render proper color swatch cards (box + label) and
  wrap output in Markup::create() so Drupal's XSS filter doesn't strip
  inline style attributes
- riverside_pt.module: scope page_attachments and page_top to
  riverside_pt.* routes only — Tailwind preflight was blowing away
  Drupal's default form styles on the login page
- settings.php: derive trusted_host_patterns from BASE_URL so the host
  and port always agree; prevents localhost:8080 being treated as untrusted
- entrypoint.sh: pass --base-url to drush site:install so Drupal stores
  the correct canonical URL from the start

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-01 03:00:19 -07:00

105 lines
3.2 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
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;
}
$attachments['#attached']['library'][] = 'riverside_pt/app';
}
function riverside_pt_theme(): array {
return [
'riverside_pt_header' => [
'variables' => [
'site_name' => NULL,
'home_url' => NULL,
'menu_items' => [],
'current_path' => NULL,
],
],
'riverside_pt_home' => [
'variables' => [],
],
];
}
function riverside_pt_page_top(array &$page_top): void {
$route = \Drupal::routeMatch()->getRouteName() ?? '';
if (!str_starts_with($route, 'riverside_pt.')) {
return;
}
$page_top['rpt_header'] = [
'#theme' => 'riverside_pt_header',
'#cache' => ['contexts' => ['url.path', 'route']],
];
}
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,
'is_cta' => ($title === 'Book An Appointment' || $title === 'Contact'),
];
}
$variables['menu_items'] = $items;
$variables['current_path'] = \Drupal::request()->getPathInfo();
}
function riverside_pt_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMatchInterface $route_match, array $context): void {
if ($route_match->getRouteName() === 'riverside_pt.booking') {
$breadcrumb = new Breadcrumb();
$breadcrumb->addLink(Link::createFromRoute('← Back', 'riverside_pt.schedule'));
$breadcrumb->addCacheContexts(['route']);
}
}
function riverside_pt_mail(string $key, array &$message, array $params): void {
if ($key !== 'booking_request') {
return;
}
$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'],
'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);
}