diff --git a/web/modules/custom/riverside_pt/js/scroll.js b/web/modules/custom/riverside_pt/js/scroll.js index e9892c9..c9eef26 100644 --- a/web/modules/custom/riverside_pt/js/scroll.js +++ b/web/modules/custom/riverside_pt/js/scroll.js @@ -15,13 +15,14 @@ function headerOffset() { return header.offsetHeight + (menuOpen ? 0 : FIXED_BUFFER); } -// On load: if the URL has a hash (e.g. /home#pt-services from another page), -// re-scroll with the correct header offset instead of the browser's native jump. +// On load: scroll to the anchor from either the URL hash or drupalSettings +// (set by the server when rendering the home page at a clean URL like /services). document.addEventListener("DOMContentLoaded", function () { - if (!window.location.hash) return; - var target = document.querySelector(window.location.hash); + var settings = window.drupalSettings && window.drupalSettings.riversidePt; + var anchor = window.location.hash || (settings && settings.scrollTo); + if (!anchor) return; + var target = document.querySelector(anchor); if (!target) return; - // Defer until layout is stable, then position correctly. requestAnimationFrame(function () { zenscroll.toY(Math.max(0, target.getBoundingClientRect().top + window.scrollY - headerOffset()), 0); }); diff --git a/web/modules/custom/riverside_pt/riverside_pt.install b/web/modules/custom/riverside_pt/riverside_pt.install index 43a0b16..0fdf9d0 100644 --- a/web/modules/custom/riverside_pt/riverside_pt.install +++ b/web/modules/custom/riverside_pt/riverside_pt.install @@ -227,18 +227,6 @@ function _riverside_pt_build_navigation(): void { } } - foreach (['FAQ'] as $title) { - if ($em->getStorage('node')->loadByProperties(['title' => $title, 'type' => 'page'])) { - continue; - } - $node = Node::create(['type' => 'page', 'title' => $title, 'status' => 1]); - $node->save(); - PathAlias::create([ - 'path' => '/node/' . $node->id(), - 'alias' => '/' . strtolower($title), - 'langcode' => 'en', - ])->save(); - } $defs = [ ['title' => 'Home', 'uri' => 'route:', 'weight' => 0, 'class' => NULL], diff --git a/web/modules/custom/riverside_pt/src/Controller/HomeController.php b/web/modules/custom/riverside_pt/src/Controller/HomeController.php index ee018f7..e9372c4 100644 --- a/web/modules/custom/riverside_pt/src/Controller/HomeController.php +++ b/web/modules/custom/riverside_pt/src/Controller/HomeController.php @@ -4,13 +4,21 @@ namespace Drupal\riverside_pt\Controller; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Url; -use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; class HomeController extends ControllerBase { - public function redirectToAnchor(Request $request): RedirectResponse { - return new RedirectResponse($request->attributes->get('destination'), 301); + // Renders the home page at a clean URL (e.g. /services, /book-appointment) + // and injects the scroll target so the client scrolls to the right section + // without a redirect — the URL stays exactly as requested. + public function redirectToAnchor(Request $request): array { + $build = $this->page(); + $destination = $request->attributes->get('destination', ''); + $hash = strstr($destination, '#'); + if ($hash !== FALSE) { + $build['#attached']['drupalSettings']['riversidePt']['scrollTo'] = $hash; + } + return $build; } public function page(): array {