Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Adding Files to Images within Image Gallery

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3
Go to End
Author Topic: 3572 Views
  • go2planC
    Avatar
    Community Member
    19 Posts

    Adding Files to Images within Image Gallery Link to this post

    Hi Uncle Cheese,

    First I'd like to say wicked job with the image gallery and DataObject Modules. 5 Star!!!!!

    Ok here's my problem, I'm currently building a site that the image gallery works perfectly for except what I need to do is to add files to each image. For Example I've got a normal gallery image, but I would like to attach multiple files such as photoshop version of it to the gallery image for the end user to download.

    Is this posible? I've been banging my head against the desk for days now and finally had to give and ask for help. So please help.

    Cheers

  • UncleCheese
    Avatar
    4085 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    Easiest thing to do..

    Create a subclass of ImageGalleryPage

    MyImageGalleryPage extends ImageGalleryPage

    protected $itemClass = "MyImageGalleryItem";

    MyImageGalleryItem extends ImageGalleryItem
    // define a has_one to your file
    function getCMSFields_forPopup()
    {
    $f = parent::getCMSFields_forPoup();
    // add file field
    return $f;
    }

  • zaighum47
    Avatar
    Community Member
    3 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    I want to do the same thing, but cannot fully grasp what UncleCheese has said. If possible could it be explained in more detail? or perhaps an alternative way. Thanks in Advance

  • UncleCheese
    Avatar
    4085 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    You just need to subclass your ImageGalleryPage and ImageGalleryItem classes so you can customise them.

    MyImageGalleryPage extends ImageGalleryPage

    protected $itemClass = "MyImageGalleryItem";

    MyImageGalleryItem extends ImageGalleryItem

    static $has_one = array ('SomeFile' => 'File');

    function getCMSFields_forPopup()
    {
    $f = parent::getCMSFields_forPoup();
    $f->push(new FileIFrameField('SomeFile');
    return $f;
    }

  • zaighum47
    Avatar
    Community Member
    3 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    Thank you UncleCheese,
    I did the following.
    1. Created a file -> MyImageGalleryPage.php in mysite/code with:

    <?php
    class MyImageGalleryPage extends ImageGalleryPage{
    protected $itemClass = "MyImageGalleryItem";
    }
    class MyImageGalleryPage_Controller extends ImageGalleryPage_Controller {

    }
    ?>


    2. Created a file -> MyImageGalleryItem.php in mysite/code with:

    <?php
    class MyImageGalleryItem extends ImageGalleryItem {
    static $has_one = array ('ABC' => 'File');

    function getCMSFields_forPopup()
    {
    $f = parent::getCMSFields_forPopup();
    $f->push(new FileIFrameField('ABC'));
    return $f;
    }
    }
    ?>


    I get some error the first time I upload a picture in the field where I should attach another file. But if I just ignore it, save the file, then open it up again, it seems to work fine.
    The problem is it doesn't show up on the slideshow anywhere with any of the configuration. I tried the same thing but with just adding another caption-> same thing will not show up on the slideshow.
    Is there anything else I should do? or did wrong?
    THANKS UNCLECHEESE! =]

    The error btw is:

    [Notice] Undefined index: uploaded_files
    GET /admin/EditForm/field/GalleryItems/EditUploadedForm/field/ABC/iframe?ctf[GalleryItems][start]=0&ctf[GalleryItems][per_page]=10&ctf[GalleryItems][showall]=0&ctf[GalleryItems][sort]=SortOrder&ctf[GalleryItems][sort_dir]=DESC&ctf[GalleryItems][search]=&ctf[GalleryItems][filter]=AlbumID_8&ctf[GalleryItems][view]=grid&ctf[GalleryItems][imagesize]=100

    Line 393 in C:\wamp\www\dataobject_manager\code\FileDataObjectManager.php
    ....
    393       $total = isset($_POST['totalsize']) ? $_POST['totalsize'] : sizeof($_POST['uploaded_files']);
    ....

    Trace

    * FileDataObjectManager->EditUploadedForm(SS_HTTPRequest)
    Line 134 of RequestHandler.php
    * RequestHandler->handleRequest(SS_HTTPRequest)
    Line 152 of RequestHandler.php
    * RequestHandler->handleRequest(SS_HTTPRequest)
    Line 152 of RequestHandler.php
    * RequestHandler->handleRequest(SS_HTTPRequest)
    Line 147 of Controller.php
    * Controller->handleRequest(SS_HTTPRequest)
    Line 283 of Director.php
    * Director::handleRequest(SS_HTTPRequest,Session)
    Line 127 of Director.php
    * Director::direct(/admin/EditForm/field/GalleryItems/EditUploadedForm/field/ABC/iframe)
    Line 127 of main.php

  • zaighum47
    Avatar
    Community Member
    3 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    Bump. =[

  • mattclegg
    Avatar
    Community Member
    56 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    I think the problem might be occurring because the post variables are not being passed to the inside of an iFrame.

    Try changing Line 493 of FileDataObjectManager.php to something like;

    if(isset($_POST['totalsize']))
       $total = $_POST['totalsize'];
    elseif(isset($_REQUEST['uploaded_files']))
       $total = sizeof($_REQUEST['uploaded_files']);
    else
       $total = 1; //Hardcode for iFrame

  • adesweb
    Avatar
    Community Member
    39 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    Hi,

    Had the same issue. This works, but the first time I upload, and then try and upload the thumbnail in the imageField, I get the following error:

    Fatal error: Call to a member function write() on a non-object in /home/adrianw/PROJECTS/bcl/website2009/sapphire/forms/FileIFrameField.php on line 209

    Please can someone help?

    Adrian

    3572 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.