Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-18686

PathPrefix is not removed from url by ezpLanguageSwitcher

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Medium Medium
    • Resolution: Unresolved
    • Affects Version/s: 4.2011
    • Fix Version/s: None
    • Labels:
      None
    • Environment:

      Operating System:Debian
      PHP Version: 5.3.3
      Database and version:
      Browser (and version): Firefox 6.0.2

      Description

      When a PathPrefix setting is set in the destination siteaccess , the destinationUrl() function in the ezpLanguageSwitcher class does not remove the PathPrefix from the $urlAlias variable.

      I used the following workaround in kernel/private/classes/ezplanguageswitcher.php :

      public function destinationUrl()
      {
      .....
      $urlAlias = $destinationElement[0]>getPath( $this>destinationLocale, $siteLanguageList );

      // remove pathPrefix from url
      $sitePathPrefix = $saIni->variable( 'SiteAccessSettings', 'PathPrefix' );
      $urlAliasArray = explode ( '/' , $urlAlias);

      if ( in_array($sitePathPrefix,$urlAliasArray) )

      { unset($urlAliasArray[0]); $urlAlias = implode('/',$urlAliasArray); }

      ......
      }

      It would be a good idea to have the pathPrefix automatically checked by the languageswitcher in future versions.

      Steps to reproduce
      • create multiple siteaccess with differents ContentObjectLocale
      • specify a PathPrefix in each siteaccess
      • translate an object
      • use the /switchlanguage/to/$destinationSiteaccess/$node_id function to get the url alias of a node in the destination siteaccess

        Issue Links

          Activity

          Hide
          Jérémy Baumgarth added a comment -

          I suggest to do the same patch in one line :
          // remove pathPrefix from url
          $urlAlias = implode( '/',array_diff( explode ( '/' , $urlAlias ), array( $saIni->variable( 'SiteAccessSettings', 'PathPrefix' ) ) ) );

          Then, you should not modify kernel classes, instead override settings in site.ini file :
          [RegionalSettings]
          LanguageSwitcherClass=MYLanguageSwitcher

          The class MYLanguageSwitcher remains the same, just put the patch on line 155.
          Regenerate autoloads and clear the cache

          Have fun

          Show
          Jérémy Baumgarth added a comment - I suggest to do the same patch in one line : // remove pathPrefix from url $urlAlias = implode( '/',array_diff( explode ( '/' , $urlAlias ), array( $saIni->variable( 'SiteAccessSettings', 'PathPrefix' ) ) ) ); Then, you should not modify kernel classes, instead override settings in site.ini file : [RegionalSettings] LanguageSwitcherClass=MYLanguageSwitcher The class MYLanguageSwitcher remains the same, just put the patch on line 155. Regenerate autoloads and clear the cache Have fun
          Hide
          Steven Bressey added a comment -

          Thank you for your advice and shortening the code.
          I will update my patch asap.
          I indeed forgot about the LanguageSwitcherClass setting, hence the kernel direct patch.

          Nevertheless, I hope someone from the ez team will take this issue into account, and bring a solution in the future releases.

          Show
          Steven Bressey added a comment - Thank you for your advice and shortening the code. I will update my patch asap. I indeed forgot about the LanguageSwitcherClass setting, hence the kernel direct patch. Nevertheless, I hope someone from the ez team will take this issue into account, and bring a solution in the future releases.
          Hide
          Elie Theocari added a comment - - edited

          Hi,

          thanks for this solution that will fix the very same problem that I encountered. In my case though, I have a PathPrefix that contains a slash (my different websites have their own pages on the third level of the tree).

          In my project, the final implementation looks like :

          $urlAlias = implode( '/', array_diff( explode ( '/' , $urlAlias ), explode( '/', $saIni->variable( 'SiteAccessSettings', 'PathPrefix' ) ) ) );
          

          I agree with you Steven, it would be great if someone from eZ Systems could fix this in a future release.

          Best regards,
          Elie

          Show
          Elie Theocari added a comment - - edited Hi, thanks for this solution that will fix the very same problem that I encountered. In my case though, I have a PathPrefix that contains a slash (my different websites have their own pages on the third level of the tree). In my project, the final implementation looks like : $urlAlias = implode( '/', array_diff( explode ( '/' , $urlAlias ), explode( '/', $saIni->variable( 'SiteAccessSettings', 'PathPrefix' ) ) ) ); I agree with you Steven, it would be great if someone from eZ Systems could fix this in a future release. Best regards, Elie

            People

            • Assignee:
              unknown
              Reporter:
              Steven Bressey
            • Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: