Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Extending Image on Nested ImageDOM

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 750 Views
  • zenmonkey
    Avatar
    Community Member
    524 Posts

    Extending Image on Nested ImageDOM Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Extending Image on Nested ImageDOM Link to this post

    Where is the DOM? On Product? Do you have that code?

  • zenmonkey
    Avatar
    Community Member
    524 Posts

    Re: Extending Image on Nested ImageDOM Link to this post

    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);

    750 Views
Page: 1
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.