mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-04 05:44:58 +00:00
Add form and types to handle async files
This commit is contained in:
@@ -14,13 +14,10 @@ namespace Chill\DocStoreBundle\Form;
|
||||
use Chill\DocStoreBundle\Entity\AccompanyingCourseDocument;
|
||||
use Chill\DocStoreBundle\Entity\Document;
|
||||
use Chill\DocStoreBundle\Entity\DocumentCategory;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Form\Type\ChillTextareaType;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
@@ -29,33 +26,9 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class AccompanyingCourseDocumentType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $authorizationHelper;
|
||||
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
protected $om;
|
||||
|
||||
/**
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
/**
|
||||
* the user running this form.
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
public function __construct(
|
||||
TranslatableStringHelper $translatableStringHelper
|
||||
) {
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
private readonly TranslatableStringHelperInterface $translatableStringHelper
|
||||
) {}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
|
@@ -20,23 +20,15 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class DocumentCategoryType extends AbstractType
|
||||
{
|
||||
private $chillBundlesFlipped;
|
||||
|
||||
public function __construct($kernelBundles)
|
||||
{
|
||||
// TODO faire un service dans CHillMain
|
||||
foreach ($kernelBundles as $key => $value) {
|
||||
if (str_starts_with((string) $key, 'Chill')) {
|
||||
$this->chillBundlesFlipped[$value] = $key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$bundles = [
|
||||
'chill-doc-store' => 'chill-doc-store',
|
||||
];
|
||||
|
||||
$builder
|
||||
->add('bundleId', ChoiceType::class, [
|
||||
'choices' => $this->chillBundlesFlipped,
|
||||
'choices' => $bundles,
|
||||
'disabled' => false,
|
||||
])
|
||||
->add('idInsideBundle', null, [
|
||||
@@ -44,7 +36,7 @@ class DocumentCategoryType extends AbstractType
|
||||
])
|
||||
->add('documentClass', null, [
|
||||
'disabled' => false,
|
||||
]) // cahcerh par default PersonDocument
|
||||
])
|
||||
->add('name', TranslatableStringFormType::class);
|
||||
}
|
||||
|
||||
|
@@ -11,7 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\DocStoreBundle\Form;
|
||||
|
||||
use ChampsLibres\AsyncUploaderBundle\Form\Type\AsyncUploaderType;
|
||||
use Chill\DocStoreBundle\Form\Type\AsyncUploaderType;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
@@ -26,15 +26,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
*/
|
||||
class StoredObjectType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
protected $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
public function __construct(private readonly EntityManagerInterface $em) {}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
|
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\DocStoreBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
class AsyncUploaderType extends AbstractType
|
||||
{
|
||||
private readonly int $expires_delay;
|
||||
private readonly int $max_submit_delay;
|
||||
private readonly int $max_post_file_size;
|
||||
|
||||
public function __construct(
|
||||
private readonly UrlGeneratorInterface $url_generator,
|
||||
ParameterBagInterface $parameters,
|
||||
) {
|
||||
$config = $parameters->get('chill_doc_store')['openstack']['temp_url'];
|
||||
|
||||
$this->expires_delay = $config['max_expires_delay'];
|
||||
$this->max_submit_delay = $config['max_submit_delay'];
|
||||
$this->max_post_file_size = $config['max_post_file_size'];
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'expires_delay' => $this->expires_delay,
|
||||
'max_post_size' => $this->max_post_file_size,
|
||||
'submit_delay' => $this->max_submit_delay,
|
||||
'max_files' => 1,
|
||||
'error_bubbling' => false,
|
||||
]);
|
||||
|
||||
$resolver->setAllowedTypes('expires_delay', ['int']);
|
||||
$resolver->setAllowedTypes('max_post_size', ['int']);
|
||||
$resolver->setAllowedTypes('max_files', ['int']);
|
||||
$resolver->setAllowedTypes('submit_delay', ['int']);
|
||||
}
|
||||
|
||||
public function buildView(
|
||||
FormView $view,
|
||||
FormInterface $form,
|
||||
array $options
|
||||
) {
|
||||
$view->vars['attr']['data-async-file-upload'] = true;
|
||||
$view->vars['attr']['data-generate-temp-url-post'] = $this
|
||||
->url_generator->generate('async_upload.generate_url', [
|
||||
'expires_delay' => $options['expires_delay'],
|
||||
'method' => 'post',
|
||||
'submit_delay' => $options['submit_delay'],
|
||||
]);
|
||||
$view->vars['attr']['data-temp-url-get'] = $this->url_generator
|
||||
->generate('async_upload.generate_url', ['method' => 'GET']);
|
||||
$view->vars['attr']['data-max-files'] = $options['max_files'];
|
||||
$view->vars['attr']['data-max-post-size'] = $options['max_post_size'];
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return HiddenType::class;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user