silverstripe / silverstripe-asset-admin

Silverstripe assets gallery for asset management
BSD 3-Clause "New" or "Revised" License
20 stars 79 forks source link

Add ability to attach a dedicated form schema to an UploadField #1021

Open maxime-rainville opened 4 years ago

maxime-rainville commented 4 years ago

The HTMLEditor will allow you to open an InsertMediaModal to pick an image to insert in the WYSIWYG. This modal also allow you to specify context specific information about the image (caption, size, placement, etc).

When working with an UploadField, you will occasionally require similar context specific bits of metadata to attach to the Image. Right now, you have to edit these extra bits of data in other fields. In a perfect world, you would be able to provide those extra bits of information directly in the insert modal.

Possible use case

What the API could look like

<?php

# Single image
$uploadField = UploadField::create('MyHeroImage');

$imageForm = new Form($someController, 'SubImageForm, $someListOfFields, $someListOfAction);

$uploadField->attachSubForm();

# Many images

class FileList extends DataObject
{
    private static $many_many = [
        "Documents" => [
            'through' => FileListEntry::class,
            'from' => 'FileList',
            'to' => 'File',
        ]
    ];

    public function getCMSFields() {
        $fields = parent::getCMSFields();

        // In this case, the UploadField would be smart enough to realise that when
        // provided a `many_many` or `many_many_through` relationship to an File object,
        // it should take all the other fields and stick them in a dedicated form.
        $fields->addFieldToTab('Root.Main', UploadField::create('Documents');
        return $fields;
    }
}

class FileListEntry extends DataObject
{
    private static $db = [
        'Description' => 'Text',
        'Copyright' => 'Text',
    ];

    private static $has_one = [
        'FileList' => FileList::class,
        'File' => File::class,
    ];
}
maxime-rainville commented 4 years ago

@silverstripeux Let me know if you think this is a potentially worthwhile idea and I can flesh it out a bit more.

Probably somewhat related to https://github.com/silverstripe/silverstripe-asset-admin/issues/813

clarkepaul commented 4 years ago

I do think this would allow more flexibility but as for priority, I'm not certain? In my case, I would like to use the extra field for ALT text which is only relevant to this UploadField's placement (due to upload field images lacking accessibility).

If this gets more interest I'd like to incorporate it into our designs first (although I don't see it being an issue UI-wise as it already functions like that with TinyMCE fields). Added to our design backlog FYI