Repository navigation
fix(quant_search): publish a search page on every save, and suggest a better search box region - #270
Merged
Merged
Conversation
… better search box region Saving a search page published it only from the two forms, so a page saved by drush, a recipe, a config import or code stayed stale on Quant until the next seed. The entity insert and update hooks now call the publisher, like node saves: a save publishes, a disable unpublishes, and a changed route withdraws the old address. Delete already unpublished. "Create a search page" placed the search box in the header region. In Olivero that region holds the logo; Olivero keeps its own search box in the secondary menu region. The form now suggests secondary_menu, then the region of the theme's core search box, then the header, and names the suggestion.
…Quant is enabled The search page hooks published during the save, ignored quant_enabled and let a Quant API error break the save or a config import. They now schedule the work in a shutdown function, as node saves do: it runs only with quant_enabled on and a token, after the request (so after a config import), once per page, never during installation or in maintenance mode, and a Quant error is logged and recorded as a push failure. Delete is guarded the same way. A moved page redirects its old address to the new one, unless another page uses the old address now. The edit form refuses an address in use. The region suggestion counts only enabled core search boxes and says when the box will sit next to one, and the box choice needs the block module.
… maintenance mode The route of a search page is stored without slashes at either end and in lower case, and the edit form compares routes the same way, because Quant paths do not depend on case. A change of case only is not a move. A change made during installation or in maintenance mode is listed with the push failures, with its own reason, so editors see that it is not on Quant. The publisher resolves the domain before it reads quant_enabled and the token, catches every error per page and of the router rebuild, keeps the pending pages across a container rebuild, and marks the router for rebuild on delete. The fake API records calls under a lock.
…vious route Drupal routes depend on case, so lowercasing the stored route broke links to /Search on the site after the next save. The route is now stored trimmed of spaces and slashes only, and routes are compared without case wherever the address on Quant matters (the edit form, the old address of a moved page, an address in use). The previous route is trimmed too, so a route stored as /search/ unpublishes /search. A failure to list a change left in maintenance mode or installation is logged and does not break the save.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug A: saving a search page did not always republish it
Cause. Only the two forms published a search page:
QuantSearchPageForm::save()(modules/quant_search/src/Form/QuantSearchPageForm.php:498on 2.x) andCreateSearchPageForm::submitForm()(CreateSearchPageForm.php:296). The module had a delete hook but no insert or update hook. A page saved any other way (drush, a recipe,config:import, custom code) stayed stale on Quant until the next seed. Node saves do not have this gap:quant_node_update()publishes from the entity hook.Reproduced on a Drupal 11.4 site with a Quant connection, with a listener that records and stops Quant events before they are sent:
$page->save()dispatched nothing; a submit of the edit form dispatched oneOUTPUTfor the route.Fix.
quant_search.module: the insert, update and delete hooks callquant_search.page_publisher(schedule()andscheduleDelete()). The forms no longer call the publisher.SearchPagePublisherworks like a node save:quant.settings:quant_enabledis on and the site has a token. Delete is guarded the same way now; before, it unpublished on every site. Under drush,CliDomainContext::initialize()runs before these checks, so a domain's settings and token decide.quant_shutdown, which runspublishPending(). A config import is complete before a page renders, and several saves of one page in a request publish once. Config import saves (isSyncing()) publish too.\Throwable) of a page (facet registration, render, API) is logged and recorded in the push failures list. A router rebuild error is logged. Neither breaks a save or an import.PushFailures::record()takes an optional reason for this.QuantSearchPageForm::validateForm()refuses an address that another search page uses, compared without slashes and case (QuantSearchPage::routeKey()), because Quant paths do not depend on case.QuantSearchPage::preSave()stores the route without spaces or slashes at either end (QuantSearchPage::normaliseRoute()) and keeps its case, because Drupal routes depend on case. The publisher compares routes the same way, and trims the previous route too, so a route stored as/search/before this change unpublishes/search. A change of case only is not a move: nothing is unpublished or redirected.Bug B: the search box defaulted to the header region
Cause.
CreateSearchPageForm::buildBlockChoice()(CreateSearchPageForm.php:215on 2.x) choseheaderwhen the theme has that region. In Olivero and themes based on it, the header region holds the logo. Olivero puts its own search box (olivero_search_form_wide) insecondary_menu, at the end of the main menu row.Fix.
CreateSearchPageForm::defaultRegion()suggests, in this order:secondary_menu; the region of an enabled core search box (search_form_block) in the theme;header; the first region. The region field says which region it suggests, links to Block layout, and says so when the Quant box will sit next to the Drupal search box. The search box choice shows only when the block module is installed (the module does not depend on it).Tests
tests/src/Functional/SearchPagePublishTest.php(16 tests;setUp()empties the publisher's static pending list):quant_enabledoff, insert, update, disable and delete send nothing;/Search/);CreateSearchPageTest: the create form publishes once; three tests for the region suggestion (Olivero; a theme with an enabled core search box, where a disabled one does not count; neither).tests/src/Traits/WaitsForQuantCallsTrait.php: the test web server answers before shutdown functions run, so form tests wait for the publish call, then 3 more seconds so that a late duplicate fails the once-checks.CreateSearchPageTest::tearDown()waits for the publish of each page the form created, so a publish never writes into a removed test site.Quant-Urlheader (unpublish), records calls under a lock (a publish after the response runs at the same time as the next test request), and can answer every call with a 500.phpcs --standard=Drupalwith the CI extensions: clean.RELEASE-NOTES-2.3.1.mddescribes the change for site owners.PR #268
This PR is based on 2.x. Both PRs change
quant_search_quant_search_page_delete(). #268 adds the removal of the page's search boxes after the unpublish line, and this PR replaces that line withscheduleDelete($entity). Whichever merges second needs a small conflict resolution in that function: keepscheduleDelete($entity)and #268's block removal. The other files merge without conflicts.Open points
secondary_menushares the menu row. With a long main menu the row wraps and Olivero switches to the mobile menu, as it does for the box inheader. On a test site with seven top-level items at 1920 px, the row needed about 8 px more. A narrower box or fewer menu items fixes it. Olivero's own search avoids this with a toggle button.secondary_menuis inside the menu drawer, as Olivero's own search is. A box inheaderstays on the top bar./fr/search) are not published or withdrawn on save; a seed still covers them.CliDomainContext(--uri). A save in a web request publishes to the project of the request's host, as node saves do. On a multi-domain site a search page is not tied to a domain, so it publishes to the project of whichever domain saved it.drush updbanddrush si --existing-config: installation is skipped (logged). An update hook that saves a page publishes after the update run, through the site's local webserver setting.