Skip to content

Commit

Permalink
fix: convert file links in src_path
Browse files Browse the repository at this point in the history
  • Loading branch information
theus77 committed Sep 21, 2024
1 parent c77a2fd commit 82433b0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion EMS/core-bundle/src/Twig/AppExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<hash>[^\n\r"\'\?]*)(?:\?(?P<query>(?:[^\n\r"|\']*)))?/i',
function ($matches) use ($path, $asFileName) {
if ($asFileName) {
Expand Down Expand Up @@ -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:\/\/(?P<key>file:([^\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
Expand Down

0 comments on commit 82433b0

Please sign in to comment.