Domain Path Pathauto¶
Domain Path Pathauto integrates Pathauto with Domain Path so that automatic URL aliases are generated per domain. When enabled, each domain path field gains a Generate automatic URL alias checkbox, and Pathauto patterns are applied independently for every domain the entity is published to.
Requirements¶
- Domain Path (parent module)
- Pathauto
Installation¶
Enable the module:
drush en domain_path_pathauto
The module sets its weight to 11 (one above Pathauto's weight of 10) to ensure it runs after Pathauto during entity operations.
How it works¶
Per-domain automatic aliases¶
Without this submodule, Pathauto generates a single alias per entity per language. Domain Path Pathauto extends this so that each domain gets its own automatically generated alias:
| Domain | Pathauto result |
|---|---|
example.com |
/news/my-article |
blog.example.com |
/news/my-article |
The alias pattern is the same (since Pathauto patterns are not
domain-specific), but uniqueness is enforced per domain. If
/news/my-article is already taken on blog.example.com by a different
entity, the alias becomes /news/my-article-0.
The pathauto checkbox¶
Each domain path field in the entity form gains a checkbox:
Generate automatic URL alias for example.com
- Checked (default for new entities) — Pathauto generates the alias; the alias text field is disabled.
- Unchecked — the alias text field is editable and Pathauto will not override it.
This state is tracked per domain, per entity. You can have automatic aliases on some domains and manual aliases on others for the same node.
State persistence¶
The pathauto state (automatic vs. manual) is stored in the key-value store with domain-scoped collections:
domain_path_pathauto_state.{domain_id}.{entity_type}
This ensures that toggling pathauto on one domain does not affect other domains.
Architecture¶
Service decorators¶
The submodule decorates two Pathauto services:
| Decorator | Decorates | Purpose |
|---|---|---|
domain_path_pathauto.generator |
pathauto.generator |
Intercepts updateEntityAlias() to generate aliases for each domain |
domain_path_pathauto.alias_storage_helper |
pathauto.alias_storage_helper |
Adds loadBySourceAndDomain() and domain-aware save() |
Additionally, a standalone service handles domain-scoped uniqueness:
| Service | Purpose |
|---|---|
domain_path_pathauto.alias_uniquifier |
Ensures aliases are unique within a domain (appends -0, -1, etc.) |
Field type and widget overrides¶
The submodule uses hook_field_info_alter() and hook_field_widget_info_alter()
to replace the domain_path field classes:
| Original class | Replaced by | Added behavior |
|---|---|---|
DomainPathItem |
DomainPathautoItem |
Adds pathauto property; skips parent postSave() when pathauto is active |
DomainPathFieldItemList |
DomainPathautoFieldItemList |
Initializes pathauto state on new entities; purges state on delete |
DomainPathWidget |
DomainPathautoWidget |
Adds per-domain pathauto checkbox |
Alias generation flow¶
When an entity is saved with pathauto enabled for a domain:
DomainPathautoGenerator::updateEntityAlias()is called.- It delegates to the inner generator for the default (non-domain) alias.
- It calls
updateEntityDomainAlias(), which iterates domain_path field items. - For each item where pathauto state is
CREATE:- The Pathauto pattern is resolved via token replacement.
hook_pathauto_alias_alter()is invoked (with domain context).DomainAliasUniquifier::uniquify()ensures the alias is unique on that domain.DomainAliasStorageHelper::save()creates or updates the path alias with thedomain_id.
- Items where pathauto state is
SKIPare left toDomainPathItem::postSave()for manual alias handling.
Cleanup on deletion¶
- Entity deletion — all domain-specific aliases and pathauto state entries are removed.
- Domain deletion — all pathauto state entries for that domain (across all entity types) are purged from the key-value store.
Extending¶
Altering the generated alias¶
Use hook_pathauto_alias_alter() as usual. The $context array includes a
domain_id key when the alias is generated by this submodule:
function mymodule_pathauto_alias_alter(&$alias, array &$context) {
if (!empty($context['domain_id'])) {
// Alter alias for a specific domain.
}
}
Altering the pattern¶
Use hook_pathauto_pattern_alter() to modify the pattern before token
replacement. The $context array also includes domain_id.