Jump to:

5522 Posts in 1734 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Attach an image to a new Page/Dataobject

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2 3
Go to End
Author Topic: 3007 Views
  • Martin D.
    Avatar
    Community Member
    21 Posts

    Attach an image to a new Page/Dataobject Link to this post

    This is as much as a question as it is a request. If a Page, or a Dataobject has a UploadField, for an image for example, the user is not allowed/able to use them before the Page/DataObject is created and saved.

    I am sure I am not the only one who thinks that it is not user friendly to force the user to first create a page before being able to attach an image. As a developer, I understand that the relationship can't be established before the page is in the database but it doesn't make sense for the end user.

    Does anyone know if it is going to change in the near future?

    A short term solution I found is to only show the UploadField(s) if the page exists in the database:

    public function getCMSFields() {
    $fields = new FieldList();
    $imageUploadField = new UploadField('Image');
    $videoUploadField = new UploadField('Video');

    $imageUploadField->setConfig('allowedMaxFileNumber', 1);
    $videoUploadField->setConfig('allowedMaxFileNumber', 1);

    $fields->push(new TextField('Title'));
    $fields->push(new HTMLEditorField('Content'));

    if ($this->ID) {
    $fields->push($imageUploadField);
    $fields->push($videoUploadField);
    }

    $fields->push(new TextField('Source'));
    $fields->push(new TextareaField('Embed', 'Video embed code'));

    return $fields;
    }

    Thanks

  • camfindlay
    Avatar
    Forum Moderator
    148 Posts

    Re: Attach an image to a new Page/Dataobject Link to this post

    Hey Martin, yes I completely agree with you... as a developer logically I know I cannot create a relationship between a file and a record if the ID for the record doesn't exist... but from a user experience in the CMS this is a terrible workflow.

    I would be interested in any solutions or brainstormed possible ideas to fix this... is there any way to during the write process hold on to the ID of the file or image and create the relationship during or after the initial write?

    pseudo-code:

    on write

    if dataobject has a file uploaded

    hold on to a reference of the files ID number

    write the dataobject to the DB

    callback the file ID into the dataobject

    write this relationship to the DB.

    ... also how would we deal with a has_many files?
    the UploadFIeld allows us to quickly attach a bunch of files during the creation process but the supporting workflow isn't quite right yet.

    Would it be as simple as on add new it actually creates the row in the DB first up? Im happy to delete of edit rows that get added and not used... any way to turn that ability on in SS?

  • camfindlay
    Avatar
    Forum Moderator
    148 Posts

    Re: Attach an image to a new Page/Dataobject Link to this post

    I've added this ticket to the issue tracker... maybe it will get tackled at some point... it's a tricky one but would be a good win to get this UX really nice.

    http://open.silverstripe.org/ticket/7917

  • Martin D.
    Avatar
    Community Member
    21 Posts

    Re: Attach an image to a new Page/Dataobject Link to this post

    Good input camfindlay. Your solution would be, I think, pretty easy to implement by using hidden inputs containing the image/file ID's. It would be great to hear from a Silverstripe developer.

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Attach an image to a new Page/Dataobject Link to this post

    I'm with you guys on this one. Especially since the file is uploaded properly and gets an id before the page/dataobject is saved this really shouldn't be an issue that's that hard to solve and I just blindly assumed it was (just trying SS3 for the first time today). Since something has gone wrong and the upload field shows up during record creation now it gets really confusing.

    I'll be digging into the code in the weekend and hopefully we can get this solved somehow.

  • Martin D.
    Avatar
    Community Member
    21 Posts

    Re: Attach an image to a new Page/Dataobject Link to this post

    Yes, that's the other issue. The files/images are uploaded but not added to the new page. Most users will end up uploading the same file twice.

  • fabrizioT
    Avatar
    Community Member
    2 Posts

    Re: Attach an image to a new Page/Dataobject Link to this post

    Hi all,

    i'm new on Silverstripe and this is (sadly) my first post.

    The issue portrayed here is a very bad problem in my opinion, i wonder if/when it will be fixed.
    I can't even think of forcing my customers to do a 2 steps data insertion just to add some media to a newly created page.

    I highly hope in your efforts, MarcusDalgren.

  • Martin D.
    Avatar
    Community Member
    21 Posts

    Re: Attach an image to a new Page/Dataobject Link to this post

    It would be great if one of the developers of Silverstripe could help us locating the "save" method that's being called when the user create a new page.

    Thanks

    3007 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.