Skip to content

Commit

Permalink
EZP-29857: Unable to upload audio to Media field type (ezsystems#276)
Browse files Browse the repository at this point in the history
* EZP-29857: Unable to upload audio to Media field type

* EZP-29990: add const visibility
  • Loading branch information
ViniTou committed Feb 1, 2019
1 parent db8810d commit f6e1c99
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/FieldType/Mapper/MediaFormMapper.php
Expand Up @@ -30,6 +30,9 @@ class MediaFormMapper implements FieldDefinitionFormMapperInterface, FieldValueF
/** @var MaxUploadSize */
private $maxUploadSize;

protected const ACCEPT_VIDEO = 'video/*';
protected const ACCEPT_AUDIO = 'audio/*';

public function __construct(FieldTypeService $fieldTypeService, MaxUploadSize $maxUploadSize)
{
$this->fieldTypeService = $fieldTypeService;
Expand Down Expand Up @@ -80,6 +83,10 @@ public function mapFieldValueForm(FormInterface $fieldForm, FieldData $data)
$formConfig = $fieldForm->getConfig();
$fieldType = $this->fieldTypeService->getFieldType($fieldDefinition->fieldTypeIdentifier);

$acceptedFormat = Type::TYPE_HTML5_AUDIO === $fieldDefinition->fieldSettings['mediaType']
? self::ACCEPT_AUDIO
: self::ACCEPT_VIDEO;

$fieldForm
->add(
$formConfig->getFormFactory()->createBuilder()
Expand All @@ -89,6 +96,9 @@ public function mapFieldValueForm(FormInterface $fieldForm, FieldData $data)
[
'required' => $fieldDefinition->isRequired,
'label' => $fieldDefinition->getName(),
'attr' => [
'accept' => $acceptedFormat,
],
]
)
->addModelTransformer(new MediaValueTransformer($fieldType, $data->value, Value::class))
Expand Down

0 comments on commit f6e1c99

Please sign in to comment.