Uploaded image for project: 'Magnolia Multisite Module'
  1. Magnolia Multisite Module
  2. MULTISITE-120

Locale aware MultiSiteRegexpVirtualURIMapping

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Neutral Neutral
    • None
    • None
    • None

      With MultiSiteRegexpVirtualURIMapping, the URI is always mapped to the default language, which ist not desirable in a multilingual environment and renders MultiSiteRegexpVirtualURIMapping effectively useless in many cases.

      An example:

      • We used MultiSiteRegexpVirtualURIMapping to map /path/username/objectname to /path?username=username&objectname=objectname
      • The desired functionality would be that /fr/path/username/objectname is mapped to /fr/path?username=username&objectname=objectname, but this is not the case because the locale is removed from the URI before the mapping is performed

      This seems like a very basic feature that should be provided by Magnolia itself. We built the following workaround for our project:

      public class LocaleAwareMultiSiteRegexpVirtualURIMapping extends MultiSiteRegexpVirtualURIMapping {
          
          @Inject
          public LocaleAwareMultiSiteRegexpVirtualURIMapping(SiteProvider siteProvider) {
              super(siteProvider);
          }
      
          @Override
          public MappingResult mapURI(final String uri, String queryString) {
              MappingResult r = super.mapURI(uri, queryString);
              if (r != null) {
                  String replaced = r.getToURI().replace("{locale}", getLocale());
                  r.setToURI(replaced);
              }
              return r;
          }
          
          private String getLocale() {
              I18nContentSupport i18nSupport = Components.getComponent(I18nContentSupport.class);
              return i18nSupport.getLocale().getLanguage();
          }
      
      }
      

      This works fine for now, but it would be great if such a feature could be incorporated into Magnolia in a future version.

        Acceptance criteria

              Unassigned Unassigned
              szihlmann Samuel Zihlmann
              Peter Mohn
              DeveloperX
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:

                  Task DoD