Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Validator for FileUpload #138

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 1 addition & 31 deletions Configuration/NodeTypes.FormElements.FileUpload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
superTypes:
'Neos.Form.Builder:FormElement': true
'Neos.Form.Builder:DefaultValueMixin': false
'Neos.Form.Builder:FileValidatorsMixin': true
postprocessors:
'Neos.Form.Builder:ResourceCollectionsPostprocessor':
postprocessor: 'Neos\Form\Builder\NodeType\ResourceCollectionsPostprocessor'
Expand All @@ -14,37 +15,6 @@
'formElement':
icon: 'icon-upload'
properties:
'allowedExtensions':
type: array
ui:
label: i18n
reloadIfChanged: true
inspector:
group: 'formElement'
editor: 'Neos.Neos/Inspector/Editors/SelectBoxEditor'
editorOptions:
values:
'pdf':
label: '.pdf'
icon: 'icon-file-pdf-o'
'xls':
label: '.xls'
icon: 'icon-file-excel-o'
'xlsx':
label: '.xlsx'
icon: 'icon-file-excel-o'
'doc':
label: '.doc'
icon: 'icon-file-text'
'docx':
label: '.docx'
icon: 'icon-file-text'
'odt':
label: '.odt'
icon: 'icon-file-text'
'csv':
label: '.csv'
icon: 'icon-file-text'
'resourceCollection':
type: string
ui:
Expand Down
10 changes: 10 additions & 0 deletions Configuration/NodeTypes.Mixin.File.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'Neos.Form.Builder:FileMixin':
abstract: true
superTypes:
'Neos.Form.Builder:ValidatorsMixin': true
childNodes:
'validators':
constraints:
nodeTypes:
'Neos.Form.Builder:FileSizeValidator': true
'Neos.Form.Builder:FileTypeValidator': true
10 changes: 10 additions & 0 deletions Configuration/NodeTypes.Mixin.FileValidators.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'Neos.Form.Builder:FileValidatorsMixin':
abstract: true
superTypes:
'Neos.Form.Builder:ValidatorsMixin': true
childNodes:
'validators':
constraints:
nodeTypes:
'Neos.Form.Builder:FileSizeValidator': true
'Neos.Form.Builder:FileExtensionValidator': true
45 changes: 45 additions & 0 deletions Configuration/NodeTypes.Validator.FileExtension.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'Neos.Form.Builder:FileExtensionValidator':
superTypes:
'Neos.Form.Builder:AbstractValidator': true
ui:
label: 'File-Extension Validator'
icon: 'icon-file-archive'
inspector:
groups:
'validator':
icon: 'icon-filter'
properties:
'allowedExtensions':
type: array
ui:
label: i18n
reloadIfChanged: true
inspector:
group: 'validator'
editor: 'Neos.Neos/Inspector/Editors/SelectBoxEditor'
editorOptions:
values:
'pdf':
label: '.pdf'
icon: 'icon-file-pdf-o'
'xls':
label: '.xls'
icon: 'icon-file-excel-o'
'xlsx':
label: '.xlsx'
icon: 'icon-file-excel-o'
'doc':
label: '.doc'
icon: 'icon-file-text'
'docx':
label: '.docx'
icon: 'icon-file-text'
'odt':
label: '.odt'
icon: 'icon-file-text'
'csv':
label: '.csv'
icon: 'icon-file-text'
'zip':
label: '.zip'
icon: 'icon-file-text'
25 changes: 25 additions & 0 deletions Configuration/NodeTypes.Validator.FileSize.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'Neos.Form.Builder:FileSizeValidator':
superTypes:
'Neos.Form.Builder:AbstractValidator': true
ui:
label: 'File-Size range Validator'
icon: 'icon-arrows-alt-h'
inspector:
groups:
'validator':
icon: 'icon-filter'
properties:
'minimum':
type: integer
defaultValue: 0
ui:
label: i18n
inspector:
group: 'validator'
'maximum':
type: integer
defaultValue: 100
ui:
label: i18n
inspector:
group: 'validator'
16 changes: 16 additions & 0 deletions Resources/Private/Fusion/Validators/FileExtensionValidator.fusion
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# See Neos\Flow\Validation\Validator\FileTypeValidator
prototype(Neos.Form.Builder:FileExtensionValidator.Definition) < prototype(Neos.Form.Builder:Validator.Definition) {
formElementType = 'Neos.Flow:FileExtension'
options {
allowedExtensions = Neos.Fusion:DataStructure {
pdf = 'pdf'
xls = 'xls'
xlsx = 'xlsx'
doc = 'doc'
docx = 'docx'
odt = 'odt'
csv = 'csv'
zip = 'zip'
}
}
}
8 changes: 8 additions & 0 deletions Resources/Private/Fusion/Validators/FileSizeValidator.fusion
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# See Neos\Flow\Validation\Validator\FileSizeValidator
prototype(Neos.Form.Builder:FileSizeValidator.Definition) < prototype(Neos.Form.Builder:Validator.Definition) {
formElementType = 'Neos.Flow:FileSize'
options {
minimum = 0
maximum = 10000000
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="" product-name="Neos.Form.Builder" source-language="en" target-language="da" datatype="plaintext">
<body>
<trans-unit id="properties.allowedExtensions" xml:space="preserve">
<source>Allowed file types</source>
<target>Tilladte filtyper</target>
</trans-unit>
</body>
</file>
</xliff>
15 changes: 15 additions & 0 deletions Resources/Private/Translations/da/NodeTypes/FileSizeValidator.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="" product-name="Neos.Form.Builder" source-language="en" target-language="da" datatype="plaintext">
<body>
<trans-unit id="properties.minimum" xml:space="preserve">
<source>Minimum value</source>
<target>Mindste værdi i bytes</target>
</trans-unit>
<trans-unit id="properties.maximum" xml:space="preserve">
<source>Maximum value</source>
<target>Højeste værdi i bytes</target>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file original="" product-name="Neos.Form.Builder" source-language="en" datatype="plaintext" target-language="de">
<body>
<trans-unit id="properties.allowedExtensions" xml:space="preserve">
<source>Allowed file types</source>
<target xml:lang="de" state="translated">Erlaubte Dateitypen</target></trans-unit>
<trans-unit id="properties.resourceCollection" xml:space="preserve">
<source>Target Resource Collection</source>
<target xml:lang="de" state="translated">Ziel "Resource Collection"</target></trans-unit>
</body>
</file>
</xliff>
13 changes: 13 additions & 0 deletions Resources/Private/Translations/de/NodeTypes/FileSizeValidator.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file original="" product-name="Neos.Form.Builder" source-language="en" datatype="plaintext" target-language="de">
<body>
<trans-unit id="properties.minimum" xml:space="preserve">
<source>Minimum value</source>
<target xml:lang="de" state="translated">Mindestwert in Bytes</target></trans-unit>
<trans-unit id="properties.maximum" xml:space="preserve">
<source>Maximum value</source>
<target xml:lang="de" state="translated">Maximalwert in Bytes</target></trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="" product-name="Neos.Form.Builder" source-language="en" datatype="plaintext">
<body>
<trans-unit id="properties.allowedExtensions" xml:space="preserve">
<source>Allowed file types</source>
</trans-unit>
</body>
</file>
</xliff>
13 changes: 13 additions & 0 deletions Resources/Private/Translations/en/NodeTypes/FileSizeValidator.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="" product-name="Neos.Form.Builder" source-language="en" datatype="plaintext">
<body>
<trans-unit id="properties.minimum" xml:space="preserve">
<source>Minimum value in bytes</source>
</trans-unit>
<trans-unit id="properties.maximum" xml:space="preserve">
<source>Maximum value in bytes</source>
</trans-unit>
</body>
</file>
</xliff>