Skip to content

Commit

Permalink
Add fallback on get_media_manager_file_path if no media manager
Browse files Browse the repository at this point in the history
  • Loading branch information
maximehuran committed May 25, 2024
1 parent 5a1a8d5 commit eaad1d2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Twig/RichEditorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ public function getFilters(): array
*/
public function getFunctions(): array
{
return [
$mediaManagerTwigExtension = $this->fileExtensionMediaManagerExists() ? [] : [
new TwigFunction('get_media_manager_file_path', [$this, 'getMediaManagerFilePath'], ['is_safe' => ['html', 'js']]),
];

return array_merge([
new TwigFunction('monsieurbiz_richeditor_list_elements', [$this, 'listUiElements'], ['is_safe' => ['html', 'js']]),
new TwigFunction('monsieurbiz_richeditor_youtube_link', [$this, 'convertYoutubeEmbeddedLink'], ['is_safe' => ['html', 'js']]),
new TwigFunction('monsieurbiz_richeditor_youtube_id', [$this, 'getYoutubeIdFromLink'], ['is_safe' => ['html', 'js']]),
Expand All @@ -90,7 +94,7 @@ public function getFunctions(): array
new TwigFunction('monsieurbiz_richeditor_get_media_without_upload_dir', [$this, 'getMediaWithoutUploadDir'], ['is_safe' => ['html', 'js']]),
new TwigFunction('monsieurbiz_richeditor_file_extension_media_manager_exists', [$this, 'fileExtensionMediaManagerExists'], ['is_safe' => ['html', 'js']]),
new TwigFunction('monsieurbiz_richeditor_file_exists', [$this, 'fileExists'], ['is_safe' => ['html', 'js']]),
];
], $mediaManagerTwigExtension);
}

/**
Expand Down Expand Up @@ -269,6 +273,12 @@ public function fileExists(string $path): bool
return file_exists($this->kernelPublicDir . $path);
}

// Fall back for twig linter if the media manager is not installed
public function getMediaManagerFilePath(string $path): string
{
return $path;
}

private function isAdmin(array $context): bool
{
/** @var ?AppVariable $app */
Expand Down

0 comments on commit eaad1d2

Please sign in to comment.