silverstripe / silverstripe-dms

Adds a Document Management System to Silverstripe
BSD 3-Clause "New" or "Revised" License
40 stars 52 forks source link

Unable to edit file immediately after uploading #53

Closed kinglozzer closed 8 years ago

kinglozzer commented 10 years ago

When attaching files to a page using the “AssetUploadField” view, if you click the “Edit” button after uploading you’ll get a server error:

Argument 1 passed to UploadField::getFileEditFields() must be an instance of File, instance of DMSDocument given

I’m not sure if this can actually be fixed in this module. Screenshot attached of the view I’m referring to.

screen shot 2014-09-18 at 10 01 03

kinglozzer commented 10 years ago

If anyone is stuck and happens to stumble upon this issue, I found a workaround (one that could be used to patch this). I needed to customise DMSUploadField quite a bit, so I subclassed it and used Injector to use my class instead.

The solution I came up with was to create my own ItemHandler and overload UploadField_ItemHandler::EditForm():

public function EditForm() {
    $file = $this->getItem();
    // Get form components
    $fields = $this->parent->getDMSFileEditFields($file);
    $actions = $this->parent->getDMSFileEditActions($file);
    $validator = $this->parent->getDMSFileEditValidator($file);
    $form = new Form(
        $this,
        __FUNCTION__, 
        $fields,
        $actions,
        $validator
    );

    $form->loadDataFrom($file);
    $form->addExtraClass('small');

    return $form;
}

Where getDMSFileEditFields, getDMSFileEditActions and getDMSFileEditValidator are methods I added to my subclass of DMSUploadField (just copied and pasted from UploadField with the type hinting removed).

jaedb commented 8 years ago

Has there been any progress on properly fixing this? @dhensby

dhensby commented 8 years ago

@kinglozzer ?

dhensby commented 8 years ago

@jaedb to answer more explicitly, I don't have a clue - I'm only lightly involved in maintaining DMS and don't actually use it in production.

This issue is coming up to 2 years old so you'd like to think it's fixed, but I guess you're asking because it's not?

I'd have thought this is more an underlying framework issue than a DMS one, but I haven't looked into it, I'm afraid.

jaedb commented 8 years ago

@dhensby I suspect the issue has flown under the radar because it's not causing critical errors. However I suspect the later versions of Silverstripe are becoming more sensitive to the issue. SS 3.3.2 + DMS just don't work well at all together.

It seems to me that the root cause is a combination of UploadField wanting a File object, and DMSDocument extending DataObject. This means DMS is always going to require hack fixes until it extends the File object or UploadField becomes more flexible.

kinglozzer commented 8 years ago

Sorry, my memory of this module is really patchy! I think you’re correct @jaedb - the issue is to do with UploadField expecting an instance of File - hence why I had to remove the type-hinting by naming the validator/action/field methods something else :/

I have no idea how best to approach fixing this, though...

xini commented 8 years ago

I think @benmanu has a fix at https://github.com/benmanu/silverstripe-dms/commit/a5e2d29e9c80d7eea9f6825764c50b8ea360e9ca?

dhensby commented 8 years ago

PR @benmanu?