Skip to content

Commit

Permalink
Merge branch '1.1'
Browse files Browse the repository at this point in the history
* 1.1:
  Improve flags support
  [Translations] Updated translations from Crowdin
  [Translations] Updated translations from Crowdin
  Update images-on-entity.rst
  Update images-on-entity.rst
  Adding validation for image uploads
  • Loading branch information
pamil committed Mar 5, 2018
2 parents c400f7f + 584ae15 commit 19e78b2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
40 changes: 40 additions & 0 deletions docs/cookbook/images/images-on-entity.rst
Expand Up @@ -395,6 +395,46 @@ and render the ``{{ form_row(form.images) }}`` field.

Learn more about customizing templates :doc:`here </customization/template>`.

13. Validation
^^^^^^^^^^^^^^

Your form so far is working fine, but don't forget about validation.
The easiest way is using validation config files under the ``AppBundle/Resources/config/validation`` folder.

This could look like this e.g.:

.. code-block:: yaml
# AppBundle\Resources\config\validation\ShippingMethodImage.yml
AppBundle\Entity\ShippingMethodImage:
properties:
file:
- Image:
groups: [sylius]
maxHeight: 1000
maxSize: 10240000
maxWidth: 1000
mimeTypes:
- "image/png"
- "image/jpg"
- "image/jpeg"
- "image/gif"
mimeTypesMessage: 'This file format is not allowed. Please use PNG, JPG or GIF files.'
minHeight: 200
minWidth: 200
This defines the validation constraints for each image entity.
Now connecting the validation of the ``ShippingMethod`` to the validation of each single ``Image Entity`` is left:

.. code-block:: yaml
# AppBundle\Resources\config\validation\ShippingMethod.yml
AppBundle\Entity\ShippingMethod:
properties:
...
images:
    - Valid: ~    
Learn more
----------

Expand Down
@@ -1 +1 @@
<i class="{{ data.code|slice(3, 2)|lower }} flag"></i> {{ data.code }} {{ data.name }}
<i class="{{ data.code|slice(-2)|lower }} flag"></i> {{ data.code }} {{ data.name }}
Expand Up @@ -4,6 +4,5 @@

{% macro fromLocaleCode(locale_code) %}
{% import _self as flags %}
{{ flags.fromCountryCode(locale_code|slice(3, 2)) }}
{% endmacro %}

{{ flags.fromCountryCode(locale_code|slice(-2)) }}
{% endmacro %}

0 comments on commit 19e78b2

Please sign in to comment.