7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Extending Image on Nested ImageDOM
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 683 Views |
-
Extending Image on Nested ImageDOM

11 December 2009 at 6:59am
I'm trying to extend the image calls on a nested ImageDOM but it doesn't seem to be working.
Here is my Image Extension
<?php
class BlurImage extends Image {function generateMainImage($gd) {
$gd->setQuality(80);
return $gd->resizeRatio(370,240);
}function generateThumbImage($gd) {
$gd->setQuality(80);
return $gd->resize(120,80);
}}
?>Then my Nested Image DataObject
<?php
class ProdImage extends DataObject
{
static $db = array (
'Name' => 'Text',
'Description' => 'Text',
'Category' => "Enum('Main, Product, HomeFeature')"
);
static $has_one = array (
'Product' => 'Product',
'Attachment' => 'File',
'Color' => 'Color',
'OImage' => 'BlurImage'
);
public function getCMSFields()
{
return new FieldSet(
new TextField('Name'),
new TextareaField('Description'),
new DropdownField('Category','Category', singleton('ProdImage')->dbObject('Category')->enumValues()),
new FileIFrameField('Attachment')
);
}
}
?>When I call $OImage.MainImage.URL I should get a URL pointing to the Resized Image.
The only call that returns anything of note is $OImage.URL which returns the path to assets folder
Any Suggestions? Am I calling it wrong the wrong functions or have I attached it wrong to the DataObject
-
Re: Extending Image on Nested ImageDOM

18 December 2009 at 8:29am
Where is the DOM? On Product? Do you have that code?
-
Re: Extending Image on Nested ImageDOM

18 December 2009 at 8:54am
ProdImage is Nested into the Color DataObject, but also used as its own DOM on Product.
Here is the Color Object used on the ColorProduct Page
class Color extends DataObject
{
static $db = array (
'ColorName' => 'Text',
'ColorHex' => 'Text',
'ColorPMS' => 'Text'
);
static $has_one = array (
'ColorProduct' => 'ColorProduct'
);
static $has_many = array (
'ProdImages' => 'ProdImage'
);
public function getCMSFields()
{
return new FieldSet(
new TextField('ColorName'),
new TextField('ColorHex'),
new TextField('ColorPMS'),
new ImageDataObjectManager(
$this,
'ProdImages',
'ProdImage',
'Attachment',
array(
'Name' => 'Name',
'Description' => 'Description',
'Category' => 'Category'
)
)
);
}
function StripColorName() {
return str_replace(" ","", $this->ColorName);
}
}And here is how it lives on the Product Page type
static $has_many = array (
'ProdImage' => 'ProdImage',
'Resources' => 'Resource',
'Reviews' => 'Review',
);...
$productImageManager = new ImageDataObjectManager(
$this, // Controller
'ProdImage', // Source name
'ProdImage', // Source class
'Attachment', // File name on DataObject
array(
'Name' => 'Name',
'Description' => 'Description',
'Category' => 'Category'
),
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
$productImageManager->setBrowseButtonText("Upload (PNG or JPG only)");
$productImageManager->setGridLabelField('Name');
$productImageManager->setPluralTitle('ProdImage');
$fields->addFieldToTab("Root.Content.ProductImages", $productImageManager);
| 683 Views | ||
|
Page:
1
|
Go to Top |

