Skip to content

Commit cc25ff5

Browse files
committed
- Added getTypeLabels to allowed mimetypes
1 parent 40ff83d commit cc25ff5

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

docs/modules/allowed-mimetypes.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ AllowedMimeTypes::getType('image/jpeg');
197197
// returns image
198198
```
199199

200+
### getTypeLabels(): array
201+
202+
Returns a list of all allowed types.
203+
204+
```php
205+
AllowedMimeTypes::getTypeLabels();
206+
// ['image' => 'Image', 'video' => 'Video'...]
207+
```
208+
200209
### getFileSizeSetting(string $file_type): string
201210

202211
Given a file type, returns the registered file size setting. If no setting is registered, falls back to `'max_upload_file_size'`.

src/Media/AllowedMimeTypes.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,20 @@ public static function registerIconPrefix(string $icon_pack, string $prefix): vo
410410
self::$icon_prefixes[$icon_pack] = $prefix;
411411
}
412412

413+
/**
414+
* Get the allowed types list
415+
*/
416+
public static function getTypeLabels(): array
417+
{
418+
$labels = [];
419+
420+
foreach (self::$allowed_mime_types as $type => $mime_types) {
421+
$labels[$type] = __(slug_to_title($type));
422+
}
423+
424+
return $labels;
425+
}
426+
413427
/**
414428
* Get all allowed types
415429
*

tests/Feature/AllowedMimeTypesTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public function it_can_check_if_a_given_mime_type_as_an_array_is_an_allowed_mime
164164
public function it_can_get_all_allowed_types()
165165
{
166166
$result = AllowedMimeTypes::getAllowedTypes();
167+
167168
$this->assertEquals([
168169
'image',
169170
'icon',
@@ -180,4 +181,26 @@ public function it_can_get_all_allowed_types()
180181
'paper',
181182
], $result);
182183
}
184+
185+
#[Test]
186+
public function it_can_get_type_labels()
187+
{
188+
$result = AllowedMimeTypes::getTypeLabels();
189+
190+
$this->assertEquals([
191+
'image' => 'Image',
192+
'icon' => 'Icon',
193+
'video' => 'Video',
194+
'audio' => 'Audio',
195+
'excel' => 'Excel',
196+
'word' => 'Word',
197+
'powerpoint' => 'Powerpoint',
198+
'pdf' => 'Pdf',
199+
'text' => 'Text',
200+
'json' => 'Json',
201+
'document' => 'Document',
202+
'zip' => 'Zip',
203+
'paper' => 'Paper',
204+
], $result);
205+
}
183206
}

0 commit comments

Comments
 (0)