From 82433b08650abbe6b37c1ed6f3a68df40c236eca Mon Sep 17 00:00:00 2001 From: Mathieu De Keyzer Date: Sat, 21 Sep 2024 11:26:05 +0200 Subject: [PATCH] fix: convert file links in src_path --- EMS/core-bundle/src/Twig/AppExtension.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/EMS/core-bundle/src/Twig/AppExtension.php b/EMS/core-bundle/src/Twig/AppExtension.php index 61ab6283c..9e184b808 100644 --- a/EMS/core-bundle/src/Twig/AppExtension.php +++ b/EMS/core-bundle/src/Twig/AppExtension.php @@ -41,6 +41,7 @@ use EMS\CoreBundle\Service\SearchService; use EMS\CoreBundle\Service\UserService; use EMS\Helpers\Standard\Color; +use EMS\Helpers\Standard\Type; use Psr\Log\LoggerInterface; use Ramsey\Uuid\Uuid; use Symfony\Component\Form\FormError; @@ -794,7 +795,7 @@ public function srcPath(string $input, bool $asFileName = false): ?string $path = $this->router->generate('ems_file_view', ['sha1' => '__SHA1__'], UrlGeneratorInterface::ABSOLUTE_PATH); $path = \substr($path, 0, \strlen($path) - 8); - return \preg_replace_callback( + $out = \preg_replace_callback( '/(ems:\/\/asset:)(?P[^\n\r"\'\?]*)(?:\?(?P(?:[^\n\r"|\']*)))?/i', function ($matches) use ($path, $asFileName) { if ($asFileName) { @@ -822,6 +823,14 @@ function ($matches) use ($path, $asFileName) { }, $input ); + $path = $this->router->generate('emsco_data_link', ['key' => '__KEY__'], UrlGeneratorInterface::ABSOLUTE_PATH); + $out = \preg_replace_callback( + '/ems:\/\/(?Pfile:([^\n\r"\'\?]*))/i', + fn ($matches) => \str_replace('__KEY__', $matches['key'], $path), + Type::string($out) + ); + + return $out; } public function internalLinks(string $input, bool $asFileName = false): ?string