I have a Drupal site with a specialised search query page that accepts about a dozen arguments as URL query parameters, most of which are optional.
Simplified routing YML file looks like this:
my_search_results_page.content: path: '/my-search' defaults: _controller: '\Drupal\my_search\Controller\MySearchResultsController::content' _title: 'Search Results' location: null type: 'any' status: 'any' filter: 'any' requirements: _permission: 'access content' _access: 'TRUE'
The url query args
filter are passed into the controller along with a bunch of others that I've ommitted for brevity. Location is a required field, hence the
null default. All of the others are optional, and will get the value
any if not specified in the query. This all works perfectly.
Now I have an additional requirement, to be able to create custom SEO-friendly preset URLs for specific search queries. For example, if they want to do a marketing push for widgets in London, they want a URL that looks like
/widgets-in-london, which would resolve to a search results page where
location is set to
type is set to Widgets.
This seems like it could be achieved relatively easily by adding an additional routing entry to the my_search.routing.yml file for each preset URL they want, and and some extra code in my controller class to manage it. But the marketing team want to be able to create and edit these URLs on the fly, which makes a code-based solution non-optimal. But I'm at a loss as to how to do it more generally.
Can anyone help me come up with a flexible solution that will allow them to set up custom routes without them having to touch the code.