Architecture¶
Domain Short URL extends the base Short URL module through service decoration. Each decorated service wraps the original and adds domain-aware behavior while delegating non-domain operations to the inner service.
Decorated services¶
DomainAwareShortUrlManager¶
Decorates ShortUrlManager. Overrides:
buildFullUrl()— uses the assigned domain's hostname and path prefix instead of the current request's hostsyncRedirects()— setsdomain_idon all created redirect entities to scope them to the correct domainresolveNodeBySlug()— finds the short URL the active domain's redirect serves: the domain's own, else one with no domain, never another domain'sgetUrlOptions()— injects the domain entity into the options array for outbound path processing
DomainAwareSlugGenerator¶
Decorates SlugGenerator. Adds:
generateAutoIncrementForDomain(string $domain_id)— generates a domain-scoped sequential slug using a per-domain State API counter whencounter_scopeisper_domainisCounterPerDomain()— tells whethercounter_scopeisper_domain, so the presave hook leaves the base module's global number alone otherwise
Base36 generation delegates directly to the inner generator since random slugs don't need domain scoping.
CounterScopeSubscriber deletes the per-domain counters from State
whenever counter_scope changes, so each one is taken again from the
highest slug on its domain.
DomainCsvColumn¶
Adds the domain column to the base CSV import, as a service tagged
shorturl.csv_column. It refuses a domain that does not exist or
that the current user may not choose, scopes slug uniqueness by
domain, finds the short URL a row updates on the row's own domain
(a row without a domain only matches a short URL without one), and
sets the domain on the node.
DomainChoiceChecker holds the rules for which domains a user may
choose. The node form's domain selector uses it too, and so does the
ShortUrlDomainChoice constraint on the domain field, which REST and
JSON:API apply.
DomainAwareVisitTracker¶
A service provider (DomainShorturlServiceProvider) swaps the class
of the base VisitTracker service for this subclass, and registers
domain_id as a column the base module's visit subscriber writes.
buildVisitFields() adds the redirect's domain_id to visits
recorded through VisitTracker::trackVisit().
Data flow¶
Visit tracking¶
- A redirect response is generated by the Domain Redirect module.
DomainShortUrlEntityHooks::redirectResponseAlter()stamps theX-Shorturl-Domain-Idheader from the redirect'sdomain_idfield, on short URL redirects only.- The base module's
ShortUrlVisitMiddlewarecollects everyX-Shorturl-*header of the response, so the visit row getsdomain_id, including for redirects served from the page cache. - The middleware strips the headers before the response reaches the client.
Slug generation (auto-increment)¶
- User creates a short URL node with a domain selected.
ShortUrlEntityHooks::nodePresave()runs first and generates a global slug.DomainShortUrlEntityHooks::nodePresave()runs after (viaOrderAfterattribute), detects the domain, and, when counters are per domain, replaces the slug with the domain's next number that no other redirect on the domain uses. It does the same when an existing short URL switches to auto-increment.- The node title is set to
{slug} @ {domain_label}.
Hook implementations¶
| Class | Hooks |
|---|---|
DomainShortUrlEntityHooks |
node_presave, redirect_response_alter |
DomainShortUrlFormHooks |
form_node_shorturl_form_alter, form_node_shorturl_edit_form_alter |
DomainShortUrlViewsHooks |
views_data_alter |
Database additions¶
The shorturl_visits table gains a domain_id column
(VARCHAR 255, indexed) added during module installation and
removed on uninstall.