This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2423 from ec-europa/ISAICP-6416-alt
- Loading branch information
Showing
5 changed files
with
64 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
web/modules/custom/joinup_core/src/PathProcessor/IdRedirectUuidProcessor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare (strict_types = 1); | ||
|
||
namespace Drupal\joinup_core\PathProcessor; | ||
|
||
use Drupal\Core\PathProcessor\InboundPathProcessorInterface; | ||
use Drupal\joinup_core\Controller\IdRedirect; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
/** | ||
* Handles joinup_core.id_redirect route case when {uuid} param contains a '/'. | ||
* | ||
* Because the joinup_core.id_redirect route's {uuid} parameter may contain one | ||
* or more slashes, we encode the URL parameter as Drupal doesn't allow slashes | ||
* in parameters, as opposed to Symfony. We revert the parameter encoding, | ||
* later, in IdRedirect::redirectToRdfEntity(). | ||
* | ||
* @see https://www.drupal.org/project/drupal/issues/2741939 | ||
* @see https://symfony.com/doc/3.4/routing/slash_in_parameter.html | ||
* @see \Drupal\joinup_core\Controller\IdRedirect::redirectToRdfEntity() | ||
*/ | ||
class IdRedirectUuidProcessor implements InboundPathProcessorInterface { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function processInbound($path, Request $request): string { | ||
if (strpos($path, '/data/') === 0 && !$request->query->has('uuid')) { | ||
preg_match('#^/data/(?<namespace>[^/]+)/(?<uuid>.+)$#', $path, $matches); | ||
if (!empty($matches['namespace']) && !empty($matches['uuid'][0]) && IdRedirect::getEntityTypeFromPersistentUriNamespace($matches['namespace'])) { | ||
return '/data/' . $matches['namespace'] . '/' . urlencode($matches['uuid']); | ||
} | ||
} | ||
return $path; | ||
} | ||
|
||
} |