Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pmelab/contextual_aliases
Drupal module to enable the same alias in different contexts.
https://github.com/pmelab/contextual_aliases
drupal drupal-8
Last synced: 19 days ago
JSON representation
Drupal module to enable the same alias in different contexts.
- Host: GitHub
- URL: https://github.com/pmelab/contextual_aliases
- Owner: pmelab
- Created: 2017-10-06T11:54:06.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-28T06:31:47.000Z (over 5 years ago)
- Last Synced: 2024-11-10T03:32:54.911Z (about 1 month ago)
- Topics: drupal, drupal-8
- Language: PHP
- Size: 37.1 KB
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- drupal-js - contextual_aliases
README
# Contextual aliases
This module allows to split Drupal's url aliases into different contexts that allow to use the *same* alias for
*different* source paths. The most prominent use case is a setup with different domains, where the same path is
supposed to point to a different node, depending on the current domain.```
http://a.com/imprint -> /node/1
http://b.com/imprint -> /node/2
http://c.com/imprint -> /node/3
```**Disclaimer:** This is an advanced module that requires coding and knowledge about cache configuration.
## How it works
When saving a new alias, the module will search for services tagged with `alias_context_resolver` that implement the
`AliasContextResolverInterface`, and use them to determine the context for a given path.```
/node/1 -> a
/node/2 -> b
/node/3 -> NULL
```It will store this path and use it for resolving paths from aliases and vice versa. There it will consult the context
resolver again to obtain the *current* context (e.g. the domain the request was sent to). If the result matches the
stored context for this alias, it will behave normal. If not, aliases will prefixed (both ways) with their context.
Non-contextual aliases remain functional, but will be picked with a lower priority.### Current context: none
```
/node/1 -> /a/imprint
/node/2 -> /b/imprint
/node/3 -> /imprint/imprint -> /node/3
```### Current context: 'a'
```
/node/1 -> /imprint
/node/2 -> /b/imprint
/node/3 -> /imprint/imprint -> /node/1
```### Current context: 'b'
```
current context: b/node/1 -> /a/imprint
/node/2 -> /imprint
/node/3 -> /imprint/imprint -> /node/2
```## How to use it
The module requires you to implement your own context resolvers and add them as services tagged with
`alias_context_resolver` and (more importantly) configure caching in a way it also respects the same contextual
information. Otherwise you will have a very bad time watching your page cache serving random pages.