Skip to content

Commit

Permalink
Merge pull request ezsystems#1055 from flovntp/EZP-23516-languages-sw…
Browse files Browse the repository at this point in the history
…itcher-and-legacy-module

Fix EZP-23516: Language switcher and legacy module
  • Loading branch information
lolautruche committed Oct 29, 2014
2 parents df5662a + 6bd0575 commit 77347e8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
27 changes: 11 additions & 16 deletions eZ/Bundle/EzPublishLegacyBundle/Routing/FallbackRouter.php
Expand Up @@ -12,10 +12,13 @@
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Psr\Log\LoggerInterface;
use RuntimeException;

class FallbackRouter implements RouterInterface
class FallbackRouter implements RouterInterface, RequestMatcherInterface
{
const ROUTE_NAME = 'ez_legacy';

Expand Down Expand Up @@ -117,26 +120,18 @@ public function generate( $name, $parameters = array(), $absolute = false )
throw new RouteNotFoundException();
}

/**
* Tries to match a URL with a set of routes.
*
* If the matcher can not find information, it must throw one of the exceptions documented
* below.
*
* @param string $pathinfo The path info to be parsed (raw format, i.e. not urldecoded)
*
* @return array An array of parameters
*
* @throws ResourceNotFoundException If the resource could not be found
* @throws MethodNotAllowedException If the resource was found but the request method is not allowed
*
* @api
*/
public function match( $pathinfo )
{
throw new RuntimeException( "The UrlAliasRouter doesn't support the match() method. Please use matchRequest() instead." );
}

public function matchRequest( Request $request )
{
$moduleUri = $request->attributes->get( 'semanticPathinfo' ) . '?' . $request->getQueryString();
return array(
"_route" => self::ROUTE_NAME,
"_controller" => "ezpublish_legacy.controller:indexAction",
"module_uri" => $moduleUri
);
}
}
14 changes: 11 additions & 3 deletions eZ/Bundle/EzPublishLegacyBundle/Routing/UrlGenerator.php
Expand Up @@ -46,17 +46,25 @@ public function getLegacyKernel()
*/
public function doGenerate( $legacyModuleUri, array $parameters )
{
// Getting query string
$uriComponents = parse_url( $legacyModuleUri );
$legacyModuleUri = isset( $uriComponents['path'] ) ? $uriComponents['path'] : '';
$queryString = isset( $uriComponents['query'] ) ? '?' . $uriComponents['query'] : '';

// Removing leading and trailing slashes
if ( strpos( $legacyModuleUri, '/' ) === 0 )
$legacyModuleUri = substr( $legacyModuleUri, 1 );
if ( strrpos( $legacyModuleUri, '/' ) === ( strlen( $legacyModuleUri ) - 1 ) )
$legacyModuleUri = substr( $legacyModuleUri, 0, -1 );

// Removing siteaccess parameter
if( isset( $parameters['siteaccess'] ) )
unset( $parameters[ 'siteaccess' ] );

list( $moduleName, $viewName ) = explode( '/', $legacyModuleUri );
$siteAccess = $this->siteAccess;

return $this->getLegacyKernel()->runCallback(
function () use ( $legacyModuleUri, $moduleName, $viewName, $parameters, $siteAccess )
function () use ( $legacyModuleUri, $moduleName, $viewName, $parameters, $queryString )
{
$module = eZModule::findModule( $moduleName );
if ( !$module instanceof eZModule )
Expand All @@ -75,7 +83,7 @@ function () use ( $legacyModuleUri, $moduleName, $viewName, $parameters, $siteAc
$unorderedParams .= "/($paramName)/$paramValue";
}

return "/$legacyModuleUri$unorderedParams";
return "/$legacyModuleUri$unorderedParams$queryString";
},
false,
false
Expand Down

0 comments on commit 77347e8

Please sign in to comment.