1414namespace MonsieurBiz \SyliusMediaManagerPlugin \Twig \Extension ;
1515
1616use MonsieurBiz \SyliusMediaManagerPlugin \Exception \FileNotFoundException ;
17+ use MonsieurBiz \SyliusMediaManagerPlugin \MonsieurBizSyliusMediaManagerPlugin ;
1718use MonsieurBiz \SyliusMediaManagerPlugin \Provider \MimeTypesProviderInterface ;
1819use MonsieurBiz \SyliusMediaManagerPlugin \Repository \FileRepositoryInterface ;
1920use MonsieurBiz \SyliusMediaManagerPlugin \Resolver \FilePathResolverInterface ;
@@ -31,11 +32,20 @@ public function __construct(
3132
3233 public function getFunctions (): array
3334 {
34- return [
35+ $ richEditorTwigExtension = $ this ->richEditorExtensionExists () ? [] : [
36+ new TwigFunction ('monsieurbiz_richeditor_get_media_without_upload_dir ' , [$ this , 'getMediaWithoutUploadDir ' ], ['is_safe ' => ['html ' , 'js ' ]]),
37+ ];
38+
39+ return array_merge ([
3540 new TwigFunction ('get_media_manager_file_path ' , [$ this , 'getMediaManagerFilePath ' ]),
3641 new TwigFunction ('get_mime_type ' , [$ this , 'getMimeType ' ]),
3742 new TwigFunction ('is_svg_image ' , [$ this , 'isSvgImage ' ]),
38- ];
43+ ], $ richEditorTwigExtension );
44+ }
45+
46+ public function richEditorExtensionExists (): bool
47+ {
48+ return MonsieurBizSyliusMediaManagerPlugin::richEditorExtensionExists ();
3949 }
4050
4151 public function getMediaManagerFilePath (string $ path ): string
@@ -71,4 +81,10 @@ public function isSvgImage(string $relativeFilePath): bool
7181 {
7282 return \in_array ($ this ->getMimeType ($ relativeFilePath ), MimeTypesProviderInterface::SVG_TYPE_MIMES , true );
7383 }
84+
85+ // Fallback for rich editor if not installed in project
86+ public function getMediaWithoutUploadDir (string $ path ): string
87+ {
88+ return $ path ;
89+ }
7490}
0 commit comments