Giter VIP home page Giter VIP logo

contextual_aliases's Introduction

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.

contextual_aliases's People

Contributors

pmelab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

monya007

contextual_aliases's Issues

Is this module still viable ?

Do you have any example to provide ?

I have this use case here where I need to select a different node revision based on the context but same alias path.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.