Skip to content

Commit

Permalink
Merge pull request #1 from Snowbaha/master
Browse files Browse the repository at this point in the history
fix: documentation + Resources for Sylius 1.9
  • Loading branch information
Mauricette authored Apr 14, 2021
2 parents 95afd8e + d4de5d1 commit 8941da0
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 3 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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'
] %}
<div class="ui two column stackable grid">
<div class="column">
<div class="ui segment">
Expand Down Expand Up @@ -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
```
31 changes: 31 additions & 0 deletions src/Form/Type/FileType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Mezcalito\SyliusFileUploadPlugin\Form\Type;

use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Symfony\Component\Form\Extension\Core\Type\FileType as SymfonyFileType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

abstract class FileType extends AbstractResourceType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->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';
}
}
4 changes: 3 additions & 1 deletion src/Model/FileInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Mezcalito\SyliusFileUploadPlugin\Model;

interface FileInterface
use Sylius\Component\Resource\Model\ResourceInterface;

interface FileInterface extends ResourceInterface
{
public function getType(): ?string;

Expand Down
1 change: 1 addition & 0 deletions src/Model/FilesAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Mezcalito\SyliusFileUploadPlugin\Model;

use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;

trait FilesAwareTrait
{
Expand Down
8 changes: 8 additions & 0 deletions src/Resources/translations/messages.en.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

sylius:
ui:
preview_file: Preview file
form:
file:
type: Type
file: File
8 changes: 8 additions & 0 deletions src/Resources/translations/messages.fr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

sylius:
ui:
preview_file: Aperçu fichier
form:
file:
type: Type
file: Fichier
5 changes: 5 additions & 0 deletions src/Resources/views/Form/fileProductTheme.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends '@MezcalitoSyliusFileUploadPlugin/Form/theme.html.twig' %}

{% block sylius_product_file_widget %}
{{ block('sylius_file_widget') }}
{% endblock %}
21 changes: 21 additions & 0 deletions src/Resources/views/Form/theme.html.twig
Original file line number Diff line number Diff line change
@@ -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 %}
<a class="ui icon teal basic button" href="{{ asset('media/file/'~form.vars.value.path) }}" target="_blank">
<i class="file show icon"></i> {{ 'sylius.ui.preview_file'|trans }}
</a>
{% endif %}

{{ form_row(form.type) }}
<label for="{{ form.file.vars.id }}" class="ui icon labeled button"><i class="cloud upload icon"></i> {{ 'sylius.ui.choose_file'|trans }}</label>
<div class="ui hidden element">
{{ form_widget(form.file) }}
</div>
<div class="ui element">
{{- form_errors(form.file) -}}
</div>
{% endapply %}
{% endblock %}

0 comments on commit 8941da0

Please sign in to comment.