Skip to content

Commit

Permalink
Merge pull request #67 from smartbooster/add_vich_uploader_helper
Browse files Browse the repository at this point in the history
Add vich_uploader helper
  • Loading branch information
mathieu-ducrot authored Jul 11, 2024
2 parents f7c60bb + 52f952f commit fc1f1a7
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
CHANGELOG
===================
## v2.5.0 - (2024-06-25)
## v2.6.0 - (2024-07-11)
### Added
- add vich_uploader translations
- add sonata templates for logo and vich download file
- `sonata_helper.html.twig` macro to centralize crud action rendering

## v2.5.0 - (2024-06-25)
### Added
- `show_history_field.html.twig` based on tailwind class + Twig `HistoryExtension` required to autocomplete some data of the history rows
- `HistoryExtension` to automaticaly add the mentioned above template on the show view of every entity that implement the `Smart\CoreBundle\Entity\HistoryInterface`
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"yokai/security-token-bundle": "^3.3",
"sentry/sentry-symfony": "^4.1",
"symfony/expression-language": "^4.4 || ^5.4 || ^6.0",
"smartbooster/core-bundle": "^1.8",
"smartbooster/core-bundle": "^1.9.0",
"vich/uploader-bundle": "^1.19 || ^2.3",
"yokai/enum-bundle": "^4.1"
},
"require-dev": {
Expand Down
1 change: 1 addition & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
Yokai\SecurityTokenBundle\YokaiSecurityTokenBundle::class => ['all' => true],
Sonata\BlockBundle\SonataBlockBundle::class => ['all' => true],
Yokai\EnumBundle\YokaiEnumBundle::class => ['all' => true],
Vich\UploaderBundle\VichUploaderBundle::class => ['all' => true],
];
3 changes: 3 additions & 0 deletions config/packages/vich_uploader.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Required for the QA lint-twig to work
vich_uploader:
db_driver: orm
Empty file removed public/.gitkeep
Empty file.
Binary file added public/images/placeholders/128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions templates/admin/base_field/list_logo.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends '@SonataAdmin/CRUD/base_list_field.html.twig' %}

{% block field %}
{% set fileNameValue = attribute(object, field_description.fieldName ~ 'Name') %}
{% if fileNameValue is null %}
{% set url = asset('bundles/smartsonata/images/placeholders/128x128.png') %}
{% set alt = 'logo' %}
{% else %}
{% set url = vich_uploader_asset(object, field_description.fieldName ~ 'File') %}
{% set alt = attribute(object, field_description.fieldName ~ 'OriginalName') %}
{% endif %}

<div class="user-block pull-left">
<img class="img-circle img-bordered-sm" src="{{ url }}" alt="{{ alt }}"/>
</div>
{% endblock %}
16 changes: 16 additions & 0 deletions templates/admin/base_field/show_embedded_image.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{# MDT Use this template if you want to display image from Smart\CoreBundle\Entity\EmbeddedFile #}

{% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %}

{% block field %}
{% set fileNameValue = value.name %}
{% if fileNameValue is null %}
{% set url = asset('bundles/smartsonata/images/placeholders/128x128.png') %}
{% set alt = 'logo' %}
{% else %}
{% set url = vich_uploader_asset(object.files, field_description.fieldName ~ 'File') %}
{% set alt = value.originalName %}
{% endif %}

<img class="img-bordered-sm" src="{{ url }}" alt="{{ alt }}"/>
{% endblock %}
14 changes: 14 additions & 0 deletions templates/admin/base_field/show_logo.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %}

{% block field %}
{% set fileNameValue = attribute(object, field_description.fieldName ~ 'Name') %}
{% if fileNameValue is null %}
{% set url = asset('bundles/smartsonata/images/placeholders/128x128.png') %}
{% set alt = 'logo' %}
{% else %}
{% set url = vich_uploader_asset(object, field_description.fieldName ~ 'File') %}
{% set alt = attribute(object, field_description.fieldName ~ 'OriginalName') %}
{% endif %}

<img class="img-bordered-sm" src="{{ url }}" alt="{{ alt }}" width="100"/>
{% endblock %}
8 changes: 8 additions & 0 deletions templates/admin/base_field/show_vich_download.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %}

{% block field %}
{% set fileNameValue = attribute(object, field_description.fieldName ~ 'Name') %}
{% if fileNameValue is not null %}
<a href="{{ vich_uploader_asset(object, field_description.fieldName ~ 'File') }}">{{ 'vich_uploader.link.download'|trans }}</a>
{% endif %}
{% endblock %}
17 changes: 17 additions & 0 deletions templates/macros/sonata_helper.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% trans_default_domain 'admin' %}

{% macro crud_action(object, action, icon) %}
{% set url = admin.generateObjectUrl(action, object) %}
{% set label = ('action.' ~ action|u.snake)|trans %}
{% if admin.isCurrentRoute('list') %}
<a href="{{ url }}" class="btn btn-xs btn-default" title="{{ label }}">
<i class="{{ icon }}"></i>
</a>
{% else %}
<li>
<a class="sonata-action-element" href="{{ url }}">
<i class="{{ icon }}"></i> {{ label }}
</a>
</li>
{% endif %}
{% endmacro %}
51 changes: 51 additions & 0 deletions translations/admin.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,43 @@
<source>field.label_data</source>
<target>Data</target>
</trans-unit>
<!-- Label -->
<trans-unit id="label.files">
<source>label.files</source>
<target>Fichiers</target>
</trans-unit>
<trans-unit id="label.logo">
<source>label.logo</source>
<target>Logo</target>
</trans-unit>
<trans-unit id="label.pdf_file">
<source>label.pdf_file</source>
<target>Fichier PDF</target>
</trans-unit>
<trans-unit id="label.image">
<source>label.image</source>
<target>Image</target>
</trans-unit>
<trans-unit id="label.image_updated_at">
<source>label.image_updated_at</source>
<target>Image mise à jour le</target>
</trans-unit>
<trans-unit id="label.image_original_name">
<source>label.image_original_name</source>
<target>Nom du fichier image</target>
</trans-unit>
<trans-unit id="label.pdf_updated_at">
<source>label.pdf_updated_at</source>
<target>PDF mise à jour le</target>
</trans-unit>
<trans-unit id="label.pdf_original_name">
<source>label.pdf_original_name</source>
<target>Nom du fichier PDF</target>
</trans-unit>
<trans-unit id="label.uuid">
<source>label.uuid</source>
<target>Identifiant technique UUID</target>
</trans-unit>

<!-- History -->
<trans-unit id="history.none">
Expand Down Expand Up @@ -299,6 +336,20 @@
</ul>
]]></target>
</trans-unit>

<!-- VichUploaderBundle (nécessaire si utilisé dans un context Symfony formulaire hors Sonata) -->
<trans-unit id="vich_uploader.link.download">
<source>vich_uploader.link.download</source>
<target>Télécharger</target>
</trans-unit>
<trans-unit id="vich_uploader.delete_confirm.image">
<source>vich_uploader.delete_confirm.image</source>
<target>Cocher pour supprimer l'image.</target>
</trans-unit>
<trans-unit id="vich_uploader.delete_confirm.pdf">
<source>vich_uploader.delete_confirm.pdf</source>
<target>Cocher pour supprimer le fichier pdf.</target>
</trans-unit>
</body>
</file>
</xliff>
10 changes: 10 additions & 0 deletions translations/messages.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@
<source>h.arc_a</source>
<target>Action d'archivage</target>
</trans-unit>

<!-- VichUploaderBundle -->
<trans-unit id="vich_uploader.delete_confirm.image">
<source>vich_uploader.delete_confirm.image</source>
<target>Cocher pour supprimer l'image.</target>
</trans-unit>
<trans-unit id="vich_uploader.delete_confirm.pdf">
<source>vich_uploader.delete_confirm.pdf</source>
<target>Cocher pour supprimer le fichier pdf.</target>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit fc1f1a7

Please sign in to comment.