2222use Symfony \Component \Form \FormBuilderInterface ;
2323use Symfony \Component \Form \FormInterface ;
2424use Symfony \Component \Form \FormView ;
25+ use Symfony \Component \Mime \MimeTypesInterface ;
2526use Symfony \Component \OptionsResolver \OptionsResolver ;
2627use Symfony \Component \Validator \Constraints as Assert ;
2728
@@ -36,16 +37,18 @@ class ImageAssetFieldType extends AbstractType
3637 /** @var \Ibexa\ContentForms\ConfigResolver\MaxUploadSize */
3738 private $ maxUploadSize ;
3839
39- /**
40- * @param \Ibexa\Contracts\Core\Repository\ContentService $contentService
41- * @param \Ibexa\Core\FieldType\ImageAsset\AssetMapper $mapper
42- * @param \Ibexa\ContentForms\ConfigResolver\MaxUploadSize $maxUploadSize
43- */
44- public function __construct (ContentService $ contentService , AssetMapper $ mapper , MaxUploadSize $ maxUploadSize )
45- {
40+ private MimeTypesInterface $ mimeTypes ;
41+
42+ public function __construct (
43+ ContentService $ contentService ,
44+ AssetMapper $ mapper ,
45+ MaxUploadSize $ maxUploadSize ,
46+ MimeTypesInterface $ mimeTypes
47+ ) {
4648 $ this ->contentService = $ contentService ;
4749 $ this ->maxUploadSize = $ maxUploadSize ;
4850 $ this ->assetMapper = $ mapper ;
51+ $ this ->mimeTypes = $ mimeTypes ;
4952 }
5053
5154 public function getName ()
@@ -116,6 +119,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
116119
117120 if (!empty ($ mimeTypes )) {
118121 $ view ->vars ['mime_types ' ] = $ mimeTypes ;
122+ $ view ->vars ['image_extensions ' ] = $ this ->getMimeTypesExtensions ($ mimeTypes );
119123 }
120124
121125 $ view ->vars ['max_file_size ' ] = $ this ->getMaxFileSize ();
@@ -144,6 +148,21 @@ private function getMaxFileSize(): float
144148
145149 return (float )$ this ->maxUploadSize ->get ();
146150 }
151+
152+ /**
153+ * @param array<string> $mimeTypes
154+ *
155+ * @return array<string, array<string>>
156+ */
157+ private function getMimeTypesExtensions (array $ mimeTypes ): array
158+ {
159+ $ extensions = [];
160+ foreach ($ mimeTypes as $ mimeType ) {
161+ $ extensions [$ mimeType ] = $ this ->mimeTypes ->getExtensions ($ mimeType );
162+ }
163+
164+ return $ extensions ;
165+ }
147166}
148167
149168class_alias (ImageAssetFieldType::class, 'EzSystems\EzPlatformContentForms\Form\Type\FieldType\ImageAssetFieldType ' );
0 commit comments