Skip to content

Commit

Permalink
Update Dropzone.js to 5.9.2 version and add configuration options (#3)
Browse files Browse the repository at this point in the history
Update Dropzone.js to 5.9.2 version. Add chunk uploading ability. Add "maxFilesize", "acceptedFiles" options. Add uploading progressbar
  • Loading branch information
Nitro-N authored Jul 4, 2021
1 parent bbaac4f commit bd4a972
Show file tree
Hide file tree
Showing 15 changed files with 317 additions and 1,879 deletions.
21 changes: 20 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,26 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$treeBuilder->root('glavweb_uploader_dropzone');
$rootNode = $treeBuilder->root('glavweb_uploader_dropzone');

$rootNode
->children()
->scalarNode('max_filesize')
->info('Max file size in Megabites')->defaultValue(256)->end()
->scalarNode('chunking')
->defaultFalse()->end()
->scalarNode('force_chunking')
->defaultFalse()->end()
->scalarNode('chunk_size')
->info('Chunk size in bits')->defaultValue(1000000)->end()
->scalarNode('parallel_chunk_uploads')
->defaultFalse()->end()
->scalarNode('retry_chunks')
->defaultFalse()->end()
->scalarNode('retry_chunks_limit')
->defaultValue(3)->end()
->end();


return $treeBuilder;
}
Expand Down
4 changes: 3 additions & 1 deletion DependencyInjection/GlavwebUploaderDropzoneExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ class GlavwebUploaderDropzoneExtension extends Extension
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$this->processConfiguration($configuration, $configs);
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');

$container->setParameter('glavweb_uploader_dropzone.config', $config);
}
}
2 changes: 1 addition & 1 deletion Form/AbstractMediaItemType.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)

$media = $view->vars['value'];
if ($media instanceof MediaInterface) {
$structuredMedia = $this->mediaStructure->getMediaStructure($media, $options['thumbnail_filter'], true, false);
$structuredMedia = $this->mediaStructure->getMediaStructure($media, $options['thumbnail_filter'], true);
$mediaSecuredId = $structuredMedia['id'];
}

Expand Down
56 changes: 47 additions & 9 deletions Form/AbstractMediaType.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
*/
abstract class AbstractMediaType extends AbstractType
{
/**
* @var array
*/
protected $config;

/**
* @var Router
*/
Expand Down Expand Up @@ -60,8 +65,9 @@ abstract class AbstractMediaType extends AbstractType
* @param UploaderManager $uploaderManager
* @param MediaStructure $mediaStructure
*/
public function __construct(Router $router, Registry $doctrine, UploaderManager $uploaderManager, MediaStructure $mediaStructure)
public function __construct(array $config, Router $router, Registry $doctrine, UploaderManager $uploaderManager, MediaStructure $mediaStructure)
{
$this->config = $config;
$this->router = $router;
$this->doctrine = $doctrine;
$this->uploaderManager = $uploaderManager;
Expand All @@ -77,15 +83,26 @@ public function buildView(FormView $view, FormInterface $form, array $options)
{
$requestId = $options['requestId'] ?: $this->generateRequestId($view);

$view->vars['requestId'] = $requestId;
$view->vars['requestId'] = $requestId;
$view->vars['maxFilesize'] = $options['max_filesize'];
$view->vars['acceptedFiles'] = $options['accepted_files'];

$view->vars['uploadUrl'] = $this->router->generate('glavweb_uploader_upload', [
$view->vars['chunkingOptions'] = [
'chunking' => $options['chunking'],
'forceChunking' => $options['force_chunking'],
'chunkSize' => $options['chunk_size'],
'parallelChunkUploads' => $options['parallel_chunk_uploads'],
'retryChunks' => $options['retry_chunks'],
'retryChunksLimit' => $options['retry_chunks_limit']
];

$view->vars['uploadUrl'] = $this->router->generate('glavweb_uploader_upload', [
'context' => $options['context'],
'thumbnail_filter' => $options['thumbnail_filter']
]);

$view->vars['deleteUrl'] = $this->router->generate('glavweb_uploader_delete');
$view->vars['editUrl'] = $this->router->generate('glavweb_uploader_edit');
$view->vars['deleteUrl'] = $this->router->generate('glavweb_uploader_delete');
$view->vars['editUrl'] = $this->router->generate('glavweb_uploader_edit');
}

/**
Expand All @@ -94,11 +111,32 @@ public function buildView(FormView $view, FormInterface $form, array $options)
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'compound' => false,
'requestId' => null,
'context' => null,
'thumbnail_filter' => null,
'compound' => false,
'requestId' => null,
'context' => null,
'thumbnail_filter' => null,
'max_filesize' => $this->config['max_filesize'],
'accepted_files' => null,
'chunking' => $this->config['chunking'],
'force_chunking' => $this->config['force_chunking'],
'chunk_size' => $this->config['chunk_size'],
'parallel_chunk_uploads' => $this->config['parallel_chunk_uploads'],
'retry_chunks' => $this->config['retry_chunks'],
'retry_chunks_limit' => $this->config['retry_chunks_limit'],
]);

$resolver->setAllowedTypes('compound', 'bool');
$resolver->setAllowedTypes('requestId', ['string', 'null']);
$resolver->setAllowedTypes('context', ['string', 'null']);
$resolver->setAllowedTypes('thumbnail_filter', ['string', 'null']);
$resolver->setAllowedTypes('max_filesize', 'int');
$resolver->setAllowedTypes('accepted_files', ['null', 'array']);
$resolver->setAllowedTypes('chunking', 'bool');
$resolver->setAllowedTypes('force_chunking', 'bool');
$resolver->setAllowedTypes('chunk_size', 'int');
$resolver->setAllowedTypes('parallel_chunk_uploads', 'bool');
$resolver->setAllowedTypes('retry_chunks', 'bool');
$resolver->setAllowedTypes('retry_chunks_limit', 'int');
}

/**
Expand Down
10 changes: 5 additions & 5 deletions Form/ImageCollectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public function buildView(FormView $view, FormInterface $form, array $options)
*/
public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);

$resolver->setDefaults([
'compound' => false,
'requestId' => null,
'context' => null,
'thumbnail_filter' => null,
'cropper_ratio' => 1
'cropper_ratio' => 1
]);

$resolver->setAllowedTypes('cropper_ratio', ['float', 'int']);
}
}
10 changes: 6 additions & 4 deletions Form/ImageType.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ public function buildView(FormView $view, FormInterface $form, array $options)
*/
public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);

$resolver->setDefaults([
'compound' => false,
'requestId' => null,
'context' => null,
'thumbnail_filter' => null,
'thumbnail_width' => 250,
'thumbnail_height' => 250,
'cropper_ratio' => 1
]);

$resolver->setAllowedTypes('thumbnail_width', 'int');
$resolver->setAllowedTypes('thumbnail_height', 'int');
$resolver->setAllowedTypes('cropper_ratio', ['float', 'int']);
}
}
10 changes: 5 additions & 5 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
services:
glavweb_uploader_dropzone.form.image_type:
class: Glavweb\UploaderDropzoneBundle\Form\ImageType
arguments: ["@router", "@doctrine", "@glavweb_uploader.uploader_manager", "@glavweb_uploader.util.media_structure"]
arguments: ["%glavweb_uploader_dropzone.config%", "@router", "@doctrine", "@glavweb_uploader.uploader_manager", "@glavweb_uploader.util.media_structure"]
tags:
- { name: form.type, alias: Glavweb\UploaderDropzoneBundle\Form\ImageType }

glavweb_uploader_dropzone.form.image_collection_type:
class: Glavweb\UploaderDropzoneBundle\Form\ImageCollectionType
arguments: ["@router", "@doctrine", "@glavweb_uploader.uploader_manager", "@glavweb_uploader.util.media_structure"]
arguments: ["%glavweb_uploader_dropzone.config%", "@router", "@doctrine", "@glavweb_uploader.uploader_manager", "@glavweb_uploader.util.media_structure"]
tags:
- { name: form.type, alias: Glavweb\UploaderDropzoneBundle\Form\ImageCollectionType }

glavweb_uploader_dropzone.form.video_type:
class: Glavweb\UploaderDropzoneBundle\Form\VideoType
arguments: ["@router", "@doctrine", "@glavweb_uploader.uploader_manager", "@glavweb_uploader.util.media_structure"]
arguments: ["%glavweb_uploader_dropzone.config%", "@router", "@doctrine", "@glavweb_uploader.uploader_manager", "@glavweb_uploader.util.media_structure"]
tags:
- { name: form.type, alias: Glavweb\UploaderDropzoneBundle\Form\VideoType }

glavweb_uploader_dropzone.form.video_collection_type:
class: Glavweb\UploaderDropzoneBundle\Form\VideoCollectionType
arguments: ["@router", "@doctrine", "@glavweb_uploader.uploader_manager", "@glavweb_uploader.util.media_structure"]
arguments: ["%glavweb_uploader_dropzone.config%", "@router", "@doctrine", "@glavweb_uploader.uploader_manager", "@glavweb_uploader.util.media_structure"]
tags:
- { name: form.type, alias: Glavweb\UploaderDropzoneBundle\Form\VideoCollectionType }

glavweb_uploader_dropzone.form.file_type:
class: Glavweb\UploaderDropzoneBundle\Form\FileType
arguments: ["@router", "@doctrine", "@glavweb_uploader.uploader_manager", "@glavweb_uploader.util.media_structure"]
arguments: ["%glavweb_uploader_dropzone.config%", "@router", "@doctrine", "@glavweb_uploader.uploader_manager", "@glavweb_uploader.util.media_structure"]
tags:
- { name: form.type, alias: Glavweb\UploaderDropzoneBundle\Form\FileType }
Loading

0 comments on commit bd4a972

Please sign in to comment.