Project

General

Profile

Actions

Feature #85378

open

EXT:form option for saving uploaded file as sys_file_reference

Added by Lidia Demin over 6 years ago. Updated 5 months ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
Form Framework
Target version:
-
Start date:
2018-06-25
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
Complexity:
Sprint Focus:
Needs Decision

Description

In #85216 we discovered two problems:
  • The description how to save an uploaded file as sys_file_reference is missing.
  • If the file field isn't mandatory and therefore empty the insert query for the sys_file_reference table throws an exception.

For the second problem the suggestion was to use a custom SaveToDatabase finisher.

I think this whole thing should be easier, especially because there are only two fields that need to be configured for the sys_file_reference table. The configuration could look something like this:

finishers:
  -
    identifier: SaveToDatabase
    options:
      table: 'tx_myext_domain_model_mymodel'
      mode:  'insert'
      elements:
        logo:
          mapOnDatabaseColumn: 'logo'
          saveAsFileReference: true
          skipIfValueIsEmpty: true

The SaveToDatabaseFinisher needs to be extended to look for those options and:
  1. Automatically performing an insert query on the sys_file_reference table with tablenames = <options.table> and fieldname = <options.elements.elementName>
  2. Skip both the setting of the field in <options.table> and the complete insert query for sys_file_reference

Related issues 2 (1 open1 closed)

Related to TYPO3 Core - Bug #85772: EXT:form SaveToDatabaseFinisher cannot handle multi value fieldsNew2018-08-07

Actions
Copied from TYPO3 Core - Task #85216: EXT:form SaveToDatabase Finisher saves files as sys_file, not as sys_file_referenceClosed2018-06-11

Actions
Actions #1

Updated by Lidia Demin over 6 years ago

If you like this idea, I could try the implementation.

Actions #2

Updated by Lidia Demin over 6 years ago

  • Copied from Task #85216: EXT:form SaveToDatabase Finisher saves files as sys_file, not as sys_file_reference added
Actions #3

Updated by Vasyl Mosiychuk over 6 years ago

Lidia Demin wrote:

If you like this idea, I could try the implementation.

Hello! Is there a any the positive solution of this?

Actions #4

Updated by Lidia Demin over 6 years ago

  • Description updated (diff)

I haven't started yet, because there was no feedback to this proposal. But seems, it just got a +1 from you ;)

Actions #5

Updated by Ralf Zimmermann over 6 years ago

I'll take a look in the next days.

Actions #6

Updated by Vasyl Mosiychuk over 6 years ago

  • Related to Bug #85772: EXT:form SaveToDatabaseFinisher cannot handle multi value fields added
Actions #7

Updated by Vasyl Mosiychuk over 6 years ago

Lidia Demin wrote:

I haven't started yet, because there was no feedback to this proposal. But seems, it just got a +1 from you ;)

Thanks!

Yes, you are right. I want to add to the DB via ext:form not only one value and two or more values. I mean this is about `type: MultiSelect` and `type: ImageUpload`. This types which can have not one value and two or more values or can to be empty.

For example, I have:

      -
        properties:
          systemCategoryUid: ''
          validationErrorMessages:
            -
              code: '1475002976'
              message: 'Min 1'
            -
              code: '1475002994'
              message: 'Max 3'
          fluidAdditionalAttributes:
            required: required
        defaultValue: ''
        type: MultiSelectSysCategory
        identifier: categories
        label: 'Categories'
        validators:
          -
            identifier: NotEmpty
          -
            options:
              minimum: '1'
              maximum: '3'
            identifier: Count
      -
        properties:
          saveToFileMount: '1:/user_upload/'
          allowedMimeTypes:
            - image/jpeg
            - image/png
            - image/bmp
          imageLinkMaxWidth: '500'
          imageMaxWidth: '500'
          imageMaxHeight: '500'
        type: ImageUpload
        identifier: attachment
        label: Attachment

and finisher:

 -
    options:
      -
        table: tx_foo_domain_model_foo
        mode: insert
        databaseColumnMappings:
          pid:
            value: '0'
          datetime:
            value: '{__currentTimestamp}'
          tstamp:
            value: '{__currentTimestamp}'
          crdate:
            value: '{__currentTimestamp}'
        elements:
          categories:
            mapOnDatabaseColumn: categories
          title:
            mapOnDatabaseColumn: title
          bodytext:
            mapOnDatabaseColumn: bodytext
          attachment:
            mapOnDatabaseColumn: fal_media
      -
        table: sys_category_record_mm
        mode: insert
        elements:
          categories:
            mapOnDatabaseColumn: uid_local
        databaseColumnMappings:
          tablenames:
            value: tx_foo_domain_model_foo
          fieldname:
            value: categories
          uid_foreign:
            value: '{SaveToDatabase.insertedUids.0}'
      -
        table: sys_file_reference
        mode: insert
        elements:
          attachment:
            mapOnDatabaseColumn: uid_local
        databaseColumnMappings:
          table_local:
            value: sys_file
          tablenames:
            value: tx_foo_domain_model_foo
          fieldname:
            value: fal_media
          tstamp:
            value: '{__currentTimestamp}'
          crdate:
            value: '{__currentTimestamp}'
          uid_foreign:
            value: '{SaveToDatabase.insertedUids.0}'
    identifier: SaveToDatabase

The identifier: categories can to pass to the DB few values but the finisher give possibility save only one value

The identifier: attachment can to pass few values too

at the moment can save only one value

I hope that you you are understood my bad English ... sorry for my English is my bad

I hope that not only I, it who want this possibility.

Actions #8

Updated by Peter Linzenkirchner over 4 years ago

I tried to save categories from a MultiCheckbox filed in sys_categories (and of course sys_category_record_mm).
https://stackoverflow.com/questions/60698065/savetodatabase-with-multicheckbox-in-form-how-to-save-values-in-sys-category-re
It seems that the problem is not fixed until now.

I tried it this way:

-
  table: sys_category_record_mm
  mode: insert
  databaseColumnMappings:
    uid_foreign:
      value: '{SaveToDatabase.insertedUids.0}'
    tablenames:
      value: 'tx_myext_mytable'
    fieldname:
      value: 'categories'
    sorting:
      value: '0'
    sorting_foreign:
      value: '1'
    uid_local:
      value: '{category.0}'
-
  table: sys_category_record_mm
  mode: insert
  databaseColumnMappings:
    uid_foreign:
      value: '{SaveToDatabase.insertedUids.0}'
    tablenames:
      value: 'tx_myext_mytable'
    fieldname:
      value: 'categories'
    sorting:
      value: '0'
    sorting_foreign:
      value: '1'
    uid_local:
      value: '{category.1}'

which works - well, kind of - but produces lots of wrong entries in sys_category_record_mm The user can choose 10 categories so i have to repeat this code ten times (up to value: '{category.9}'). For every real entry i get a correct category entry but for every category which was not selected i get an entry with uid_local: 0. In Addition there is no possibility to fill the field categories in tx_myext_mytable with the correct value (the number of selected categories).

It seems that it is not possible in the moment to write categories - or any 1:many Releation.

Actions #9

Updated by Georg Ringer 5 months ago

  • Sprint Focus set to Needs Decision
Actions

Also available in: Atom PDF