The Path Alias management API has always been part of the core path subsystem. After path alias were converted to entities, the API is now provided by the new path_alias module. This module is required in Drupal 8.8.0 and following and is planned to be made optional in Drupal 9.0.0.
To achieve this, several core services were deprecated or aliased. Specifically:
| Legacy service | New service | Status | Notes |
|---|---|---|---|
path.alias_manager |
path_alias.manager |
Deprecated | The legacy service is still available and shares its internal state with the new one to keep performance optimizations working. |
path.alias_whitelist |
path_alias.whitelist |
Aliased | The legacy service no longer exists, the old name is still available as a service alias. Service providers wishing to support also 8.7.x will need to use ContainerBuilder::findDefinition('path.alias_whitelist'). |
path_subscriber |
path_alias.subscriber |
Deprecated | The service has been deprecated and is no longer registering itself as an event subscriber but still exists for backwards compatibility. |
path_processor_alias |
path_alias.path_processor |
Deprecated | The service has been deprecated and is no longer registering itself as a path processor but still exists for backwards compatibility. |
Note: in general, event subscriber and similar services are considered internal and should not be relied upon by other code.
The following interfaces and classes were deprecated accordingly:
| Legacy interface/class | New interface/class |
|---|---|
Drupal\Core\Path\AliasManagerInterface |
Drupal\path_alias\AliasManagerInterface |
Drupal\Core\Path\AliasManager |
Drupal\path_alias\AliasManager |
Drupal\Core\Path\AliasWhitelistInterface |
Drupal\path_alias\AliasWhitelistInterface |
Drupal\Core\Path\AliasWhitelist |
Drupal\path_alias\AliasWhitelist |
Drupal\Core\EventSubscriber\PathSubscriber |
Drupal\path_alias\EventSubscriber\PathAliasSubscriber |
Drupal\Core\PathProcessor\PathProcessorAlias |
Drupal\path_alias\PathProcessor\AliasPathProcessor |
Updates required
To make code D8.8-compatible the following changes are required:
- Service providers altering or decorating the legacy
path.alias_managerservice need to do the same also with the newpath_alias.managerservice. - Service providers altering or decorating the legacy
path.alias_whitelistservice need to either switch to the newpath_alias.whitelistservice name or to useContainerBuilder::findDefinition('path.alias_whitelist')to retrieve the service definition.
To make code D9-compatible the following changes are required:
- API consumers, service providers, or service decorators need to replace the legacy service names with the new ones in all references.
- Classes implementing the legacy interfaces need to replace them with the new ones in their
implementsclause. - Interfaces or classes extending the legacy ones need to replace them with the new ones in their
extendsclause.
Most importantly, as mentioned above, the path_alias module will be optional in Drupal 9, so code should be refactored not to assume the availability of the Path Alias API or should add an explicit dependency on the path_alias module.
Comments
How do I get an aliased URL from a path (or vv) including base?
Given a path like /node/123, to get an aliased URL is this the right way?
If at first you don’t succeed, call it version 1.0.
How to update modules is not documented well at all
In particular, it seems to me that in many cases you just have to make your module incompatible with older versions of Drupal, and update your .info.yml file to have this:
benjamin, Agaric