Skip to content

Commit

Permalink
Add Video property
Browse files Browse the repository at this point in the history
  • Loading branch information
mcaskill committed Nov 17, 2020
1 parent 2800a8e commit 9913af9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
6 changes: 6 additions & 0 deletions metadata/admin/charcoal/property/video-property.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"admin": {
"input_type": "charcoal/admin/property/input/video",
"display_type": "charcoal/admin/property/display/video"
}
}
66 changes: 66 additions & 0 deletions src/Charcoal/Property/VideoProperty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Charcoal\Property;

// From 'charcoal-property'
use Charcoal\Property\FileProperty;

/**
* Video Property.
*
* The video property is a specialized file property that handles video file.
*/
class VideoProperty extends FileProperty
{
/**
* @return string
*/
public function type()
{
return 'video';
}

/**
* Retrieves the default list of acceptable MIME types for uploaded files.
*
* This method should be overriden.
*
* @return string[]
*/
public function getDefaultAcceptedMimetypes()
{
return [
'video/mp4',
'video/webm',
'video/ogg',
'video/ogv',
'video/x-matroska',
];
}

/**
* Resolve the file extension from the given MIME type.
*
* @param string $type The MIME type to resolve.
* @return string|null The extension based on the MIME type.
*/
protected function resolveExtensionFromMimeType($type)
{
switch ($type) {
case 'video/mp4':
return 'mp4';

case 'video/webm':
return 'webm';

case 'video/ogg':
case 'video/ogv':
return 'ogv';

case 'video/x-matroska':
return 'mkv';
}

return null;
}
}

0 comments on commit 9913af9

Please sign in to comment.