Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

ImageDataObjectManager popup problem


Go to End
Reply


3 Posts   1253 Views

Avatar
jondbaker

Community Member, 19 Posts

13 December 2009 at 1:23pm

Everything seems to be working fine as far as uploading the images goes, but if I click an already-uploaded image the popup appears with a preview thumbnail, the text box for 'Title' and one for 'Caption', and just below that should be the entry for 'Attachment' but instead displays this error:

[Warning] Unknown class passed as parameter
GET /public_html/jonathandbaker.com/images/iframe/Gallery/13/Attachment

Line 445 in D:\xampp\xampp\htdocs\public_html\jonathandbaker.com\sapphire\core\Object.php
Source

436 	 * Prepare static variables before processing a {@link get_static} or {@link set_static}
437 	 * call.
438 	 */
439 	private static function prepare_statics($class) {
440 		// _cache_statics_prepared setting must come first to prevent infinite loops when we call
441 		// get_static below
442 		self::$_cache_statics_prepared[$class] = true;
443 
444 		// load statics now for DataObject classes
445 		if(is_subclass_of($class, 'DataObject')) {
446 			$extensions = Object::uninherited_static($class, 'extensions');
447 			if($extensions) foreach($extensions as $extension) {
448 				if(preg_match('/^([^(]*)/', $extension, $matches)) {
449 					$extensionClass = $matches[1];
450 					DataObjectDecorator::load_extra_statics($class, $extensionClass);
451 				}

Trace

    * is_subclass_of(Crop_Thumbnail,DataObject)
      Line 445 of Object.php
    * Object::prepare_statics(Crop_Thumbnail)
      Line 269 of Object.php
    * Object::uninherited_static(Crop_Thumbnail,db)
      Line 2020 of DataObject.php
    * DataObject::has_own_table(Crop_Thumbnail)
      Line 89 of ClassInfo.php
    * ClassInfo::dataClassesFor(Image)
      Line 2258 of DataObject.php
    * DataObject->buildSQL(ParentID = '13',,,,1,)
      Line 2350 of DataObject.php
    * DataObject->extendedSQL(ParentID = '13',,,)
      Line 1144 of DataObject.php
    * DataObject->getComponentsQuery(Attachment,,,,)
      Line 1099 of DataObject.php
    * DataObject->getComponents(Attachment)
    * call_user_func_array(Array,Array)
      Line 565 of Object.php
    * Object->__call(Attachment,Array)
    * Gallery->Attachment()
    * call_user_func_array(Array,Array)
      Line 318 of ViewableData.php
    * ViewableData->obj(Attachment)
      Line 549 of Image.php
    * Image_Uploader->Image()
      Line 562 of Image.php
    * Image_Uploader->IsImage()
      Line 597 of Image.php
    * Image_Uploader->EditImageForm()
    * call_user_func_array(Array,Array)
      Line 408 of ViewableData.php
    * ViewableData->XML_val(EditImageForm,,1)
      Line 983 of ViewableData.php
    * ViewableData_Customised->XML_val(EditImageForm,,1)
      Line 38 of .cacheD..xampp.xampp.htdocs.public_html.jonathandbaker.com.sapphire.templates.Image_iframe.ss
    * include(C:\Windows\Temp\silverstripe-cacheD--xampp-xampp-htdocs-public_html-jonathandbaker.com\.cacheD..xampp.xampp.htdocs.public_html.jonathandbaker.com.sapphire.templates.Image_iframe.ss)
      Line 357 of SSViewer.php
    * SSViewer->process(ViewableData_Customised)
      Line 163 of Controller.php
    * Controller->handleAction(HTTPRequest)
      Line 129 of RequestHandler.php
    * RequestHandler->handleRequest(HTTPRequest)
      Line 119 of Controller.php
    * Controller->handleRequest(HTTPRequest)
      Line 277 of Director.php
    * Director::handleRequest(HTTPRequest,Session)
      Line 121 of Director.php
    * Director::direct(/images/iframe/Gallery/13/Attachment)
      Line 118 of main.php

Project.php

<?php
class Project extends Page {
    static $singular_name = 'Project';
    static $plural_name = 'Projects';
    static $db = array(
        'Category' => 'Varchar(100)',
        'Description' => 'Text'
    );
    static $has_one = array(
        'ProjectHolder' => 'ProjectHolder',
        'Thumbnail' => 'Crop_Thumbnail',
        'Galleries' => 'Gallery'
    );
    public function getCMSFields() {
        $categories = array(
            'WD' => 'Web Design',
            'WDV' => 'Web Development',
            'GD' => 'Graphic Design',
            'IL' => 'Illustration',
            'PT' => 'Photography'
        );
        $manager = new ImageDataObjectManager($this, 'Galleries', 'Gallery', 'Attachment', array('Title' => 'Title', 'Caption' => 'Caption'), 'getCMSFields_forPopup');
        $fields = parent::getCMSFields();
        $fields->removeFieldFromTab("Root.Content.Main","Content");
        $fields->addFieldToTab('Root.Content.Main', new DropdownField('Category','Category', $categories));
        $fields->addFieldToTab('Root.Content.Main', new TextareaField('Description'));
        $fields->addFieldToTab("Root.Content.Thumbnail Image", new ImageField('Thumbnail'));
        $fields->addFieldToTab("Root.Content.Gallery", $manager);
        return $fields;
   }
}
class Crop_Thumbnail extends Image {
    function generateProjectThumbnail($gd) {
        return $gd->resizeByWidth(400);
    }
}
class Project_Controller extends Page_Controller {}
?>

Gallery.php

<?php
class Gallery extends Image {
    static $db = array(
        'Title' => 'Text',
        'Caption' => 'Text',
    );
    static $has_one = array(
        'Project' => 'Project'
    );
    static $has_many = array(
        'Attachment' => 'Image'
    );
    public function getCMSFields_forPopup(){
      return new FieldSet(
         new TextField('Title'),
         new TextareaField('Caption'),
         new FileIFrameField('Attachment')
      );
   }
}
?>

What I've discovered is that if I delete the Crop_Thumbnail class, everything works as expected in the popup for gallery, but then 'Thumbnail' fails. Is there any reason why I wouldn't be able to have the Crop_Thumbnail class within Project.php, since it is the only file that uses it?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

13 December 2009 at 1:58pm

You've set up your model wrong.

static $has_many = array(
'Attachment' => 'Image'
);

should be

static $has_one = array(
'Attachment' => 'Image'
);

Avatar
jondbaker

Community Member, 19 Posts

13 December 2009 at 2:05pm

Thanks for the speedy response. I had debated over the $has_one when I was writing the code, and it made more sense to me because there was going to be more than one image in the gallery. I'm still a little perplexed as to why it will allow me to upload more than one image, but alas, it works.