Skip to content

Using custom file/attachment field types #398

@Dodger77

Description

@Dodger77
Q A
Bug? no
New Feature? yes
Bundle Version 2.5.4
Sulu Version 2.5.20
Browser Version n/a

Actual Behavior

There is the field type AttachmentFieldType, that is the only way to use file input elements in the SuluFormBundle because of the processing of uploaded files is tied to the field type name "attachment" (see

public const TYPE_ATTACHMENT = 'attachment';
).

AttachmentFieldType has the possiblity to restrict uploads to image, video and audio file types, but no other file type restrictions.

Expected Behavior

  • Possibility of adding custom upload/attachment field types (e.g. for different behavior/processing of uploaded files in form events)
  • Extending of the AttachmentFieldType by custom settings (e.g. other file type restrictions)

Steps to Reproduce

Is an current try to extend the AttachmentFieldType for using custom file type restriction, e.g.:

<properties xmlns="http://schemas.sulu.io/template/template"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:xi="http://www.w3.org/2001/XInclude"
            xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/properties-1.0.xsd">
    <xi:include href="../../vendor/sulu/form-bundle/Resources/config/form-fields/default_field.xml"  xpointer="xmlns(sulu=http://schemas.sulu.io/template/template)
                      xpointer(//sulu:property)"/>
    <property name="options/type" type="select" colspan="6">
        <meta>
            <title>sulu_form.attachment_restrict</title>
            <info_text>sulu_form.attachment_restrict.hint</info_text>
        </meta>
        <params>
            <param name="values" type="collection">
                <param name="image">
                    <meta>
                        <title>sulu_form.attachment.image</title>
                    </meta>
                </param>
                <param name="audio">
                    <meta>
                        <title>sulu_form.attachment.audio</title>
                    </meta>
                </param>
                <param name="video">
                    <meta>
                        <title>sulu_form.attachment.video</title>
                    </meta>
                </param>
                <param name="document">
                    <meta>
                        <title>form_dynamic.attachment.document</title>
                    </meta>
                </param>
            </param>
        </params>
    </property>
    <property name="options/max" type="number" colspan="6">
        <meta>
            <title>sulu_form.attachment_max</title>
        </meta>
    </property>
</properties>

I saw the only way in using service decoration or compiler pass.

Possible Solutions

Like in my other issue (#397) a possible solution could be the use of the FormFieldTypeConfiguration group, because it seems to be not used anywhere at the time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions