diff --git a/README.md b/README.md index 2fc2db7..0037cae 100755 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ In your `config/packages/_sylius.yaml` file, add the following ```yaml # config/packages/_sylius.yaml imports: - - { resource: "@MezcalitoSyliusFileUploadPlugin/Resources/config/app/config.yml" + - { resource: "@MezcalitoSyliusFileUploadPlugin/Resources/config/app/config.yml" } ``` > This file defines the gaufrette `filesystem` and `adapter` used by the plugin, which you can override. @@ -288,7 +288,7 @@ In order to handle the file upload you need to attach the `FilesUploadListener` # services.yml services: app.listener.files_upload: - class: Mezcalito\SyliusFileUploadPlugin\FilesUploadListener + class: Mezcalito\SyliusFileUploadPlugin\EventListener\FilesUploadListener autowire: true autoconfigure: false public: false @@ -309,6 +309,14 @@ and render the `{{ form_row(form.files) }}` field. {% from '@SyliusAdmin/Macro/translationForm.html.twig' import translationForm %} +{# Add the form theme to preview the file with the theme (there is a shortcut for 'fileProductTheme.html.twig' #} +{# Check https://symfony.com/doc/current/form/form_themes.html for help #} +{% form_theme form with [ + '@SyliusAdmin/Form/imagesTheme.html.twig', + '@MezcalitoSyliusFileUploadPlugin/Form/theme.html.twig' +] %} + +
@@ -411,3 +419,12 @@ App\Entity\ShippingMethod: ``` [1]: https://docs.sylius.com/en/latest/cookbook/images/images-on-entity.html + +### 14. Migration + +Do the database migration + +```bash +$ bin/console doctrine:migrations:diff +$ bin/console doctrine:migrations:migrate +``` diff --git a/src/Form/Type/FileType.php b/src/Form/Type/FileType.php new file mode 100644 index 0000000..b0c7707 --- /dev/null +++ b/src/Form/Type/FileType.php @@ -0,0 +1,31 @@ +add('type', TextType::class, [ + 'label' => 'sylius.form.file.type', + 'required' => false, + ]) + ->add('file', SymfonyFileType::class, [ + 'label' => 'sylius.form.file.file', + ]) + ; + } + + public function getBlockPrefix(): string + { + return 'sylius_file'; + } +} diff --git a/src/Model/FileInterface.php b/src/Model/FileInterface.php index ac3a572..a04940b 100644 --- a/src/Model/FileInterface.php +++ b/src/Model/FileInterface.php @@ -4,7 +4,9 @@ namespace Mezcalito\SyliusFileUploadPlugin\Model; -interface FileInterface +use Sylius\Component\Resource\Model\ResourceInterface; + +interface FileInterface extends ResourceInterface { public function getType(): ?string; diff --git a/src/Model/FilesAwareTrait.php b/src/Model/FilesAwareTrait.php index 3871558..01d2522 100644 --- a/src/Model/FilesAwareTrait.php +++ b/src/Model/FilesAwareTrait.php @@ -5,6 +5,7 @@ namespace Mezcalito\SyliusFileUploadPlugin\Model; use Doctrine\Common\Collections\Collection; +use Doctrine\Common\Collections\ArrayCollection; trait FilesAwareTrait { diff --git a/src/Resources/translations/messages.en.yaml b/src/Resources/translations/messages.en.yaml new file mode 100644 index 0000000..665496c --- /dev/null +++ b/src/Resources/translations/messages.en.yaml @@ -0,0 +1,8 @@ + +sylius: + ui: + preview_file: Preview file + form: + file: + type: Type + file: File diff --git a/src/Resources/translations/messages.fr.yaml b/src/Resources/translations/messages.fr.yaml new file mode 100644 index 0000000..59f45ae --- /dev/null +++ b/src/Resources/translations/messages.fr.yaml @@ -0,0 +1,8 @@ + +sylius: + ui: + preview_file: Aperçu fichier + form: + file: + type: Type + file: Fichier diff --git a/src/Resources/views/Form/fileProductTheme.html.twig b/src/Resources/views/Form/fileProductTheme.html.twig new file mode 100644 index 0000000..861ef2e --- /dev/null +++ b/src/Resources/views/Form/fileProductTheme.html.twig @@ -0,0 +1,5 @@ +{% extends '@MezcalitoSyliusFileUploadPlugin/Form/theme.html.twig' %} + +{% block sylius_product_file_widget %} + {{ block('sylius_file_widget') }} +{% endblock %} diff --git a/src/Resources/views/Form/theme.html.twig b/src/Resources/views/Form/theme.html.twig new file mode 100644 index 0000000..8f47291 --- /dev/null +++ b/src/Resources/views/Form/theme.html.twig @@ -0,0 +1,21 @@ +{% extends '@SyliusUi/Form/theme.html.twig' %} + +{% block sylius_file_widget %} + + {% apply spaceless %} + {% if form.vars.value.path|default(null) is not null %} + + {{ 'sylius.ui.preview_file'|trans }} + + {% endif %} + + {{ form_row(form.type) }} + + +
+ {{- form_errors(form.file) -}} +
+ {% endapply %} +{% endblock %}