Skip to content

Conversation

@Schuppel1
Copy link

In this PR the FileUpload FormElement getting a validators

form-builder/Configuration/NodeTypes.FormElements.FileUpload.yaml

    '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'

The code above is removed from FileUpload and become an validator
Configuration/NodeTypes.Validator.FileExtension.yaml

'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'

Another Validator is the FileSizeValidator

'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-sort-numeric-asc'
  properties:
    'minimum':
      type: integer
      defaultValue: 0
      ui:
        label: i18n
        inspector:
          group: 'validator'
    'maximum':
      type: integer
      defaultValue: 100
      ui:
        label: i18n
        inspector:
          group: 'validator'

A Mixin: FileValidatorsMixin

'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

Now inside of NEOS it looks like this:
image

Important:

Dependencies with another Package!
Neos:Form
Neos.Form/Configuration/Settings.yaml

It is needed to add the following:

          'Neos.Flow:FileSize':
            implementationClassName: Neos\Flow\Validation\Validator\FileSizeValidator
          'Neos.Flow:FileExtension':
            implementationClassName: Neos\Flow\Validation\Validator\FileExtensionValidator

to:

Neos:
  Form:
    presets:
      default:
        validatorPresets:

Neos:Form
Neos.Form/Classes/FormElements/FileUpload.php
Remove old FileExtensionValidation Code

        $fileTypeValidator = new FileTypeValidator(array('allowedExtensions' => $this->properties['allowedExtensions']));
        $this->addValidator($fileTypeValidator);

This can be removed.

Problem:

We need a migration:
for smooth use.
I'm not good with migrations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant