task: #3623015 Use HTMX attributes instead of custom JavaScript for the theme navigation

Closes #3623015

  • Links HTMX must not handle (administration, edit and delete pages, log out, Display Builder, files, dialog and download links) are rendered with hx-boost="false" from HtmxNavigationHooks: in the rendered page wrapper (so menus and links printed by components or Display Builder page layouts are covered too, like the Website Starter menus and feed link), and on the menus, links, local tasks and actions, file, image and link field URLs rendered later in placeholders.
  • UIkit closes the offcanvas and dropdowns itself when HTMX swaps the page wrapper. The offcanvas template now renders the uk-offcanvas class, so the swapped offcanvas stays hidden after HTMX settles it. Modal links keep the normal navigation, as UIkit moves open modals to the body.
  • On boosted requests the main content anchor gets autofocus (or the main element, with tabindex="-1", on Display Builder page layouts), which HTMX focuses after the swap. The response varies on the HX-Boosted header.
  • The page title is announced in a polite live region, updated with hx-select-oob.
  • assets/js/htmx-navigation.js is removed; the core/drupal.htmx dependency stays. The hooks that ThemeHooks already implements call the new class, as a theme implements each hook once.
  • The README and AGENTS.md describe the HTMX navigation without custom JavaScript.

Added in this MR:

  • Forms keep their normal submission. HTMX also boosted the forms of the page wrapper. Webforms are rendered with their own webform wrapper, so the form preprocess never reached them: the Antibot protected contact webform posted to /antibot ("Submission failed") and nothing was stored. HtmxNavigationHooks::formAlter() (called from the form_alter of PreprocessHooks) now puts hx-boost="false" on every form posting data, webforms included, and on the GET forms using Drupal AJAX. Plain GET forms (search, exposed filters) stay boosted.
  • The form action no longer carries the HTMX page state. On a page loaded by HTMX, the request query has ajax_page_state (added by core/misc/htmx/htmx-assets.js), and the form action is built from it: the page after the submission was rendered without the libraries of the previous page ("Drupal is not defined"). The form action placeholder is now rendered by HtmxNavigationHooks::renderFormAction(), without the page state. It stays a form_action_ placeholder, which Webform needs to keep its Form API fields. The redirect or the validation errors after a submission are a normal page load.
  • The theme settings page opens again. formSystemThemeSettingsAlter() declared string $form_id, but core passes NULL when it builds the settings of a theme (TypeError). It has no form ID parameter now and adds the settings once, the same way as Webtheme.
  • Cucumber is pinned to ~12.9.0 with a yarn resolutions entry, as in Webtheme: without it the install resolved Cucumber 13, which needs Node 22.
  • Tests: ThemeSettingsFormTest (functional: the settings page opens and saves, for an installed theme and for the default theme), HtmxFormSubmissionTest (unit), and the webship-js feature 01-05-02-htmx-forms.feature: the contact webform sent from a page loaded by HTMX (success message, stored submission, normal page load, no JavaScript errors), its validation errors, the core contact form, and the boosted navigation after a form. The scenarios skip when the site has no Webform or Contact module.

Testing, on a Drupal 11.4 site (PHP 8.4) with Website Starter and this branch:

  • Before the change: the contact webform, reached by the boosted navigation, ended on /antibot "Submission failed" for a valid and for an empty submission, no submission was stored; the theme settings page threw the TypeError.
  • After the change: webship-js suite in its own headless Chromium at 1920x1080: the new form scenarios and the theme settings scenario pass (5 scenarios, 62 steps). A valid submission posts to /form/contact, redirects to the front page with "Your message has been sent." and is stored; an empty submission shows the required field errors. Cucumber 12.9.0 is installed.
  • Drush and curl: the webform renders hx-boost="false" and a clean data-action on a boosted request; the theme settings page opens (200) and saves ("The configuration options have been saved.").

Checkpoints

  • File an issue
  • Addition/Change/Update/Fix
  • Testing to ensure no regression
  • Automated unit testing coverage
  • Automated functional testing coverage
  • UX/UI designer responsibilities
  • Readability
  • Accessibility
  • Performance
  • Security
  • Developer Documentation
  • User Guide Documentation
  • Reviewed by human
  • Code review by maintainers
  • Full testing and approval
  • Credit contributors
  • Review with the product owner
  • Release notes snippet
  • Release

AI-Generated: Yes

Edited by Rajab Natshah

Merge request reports

Loading
Loading