Jump to:

7939 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Help needed with DataObjectDecorator Code

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: 846 Views
  • Webdoc
    Avatar
    Community Member
    332 Posts

    Help needed with DataObjectDecorator Code Link to this post

    How to set Slider Width And Height in line of code
    swfobject.embedSWF("PieceMaker/flash/piecemaker.swf", "PieceMaker-container", "Slider Width here", "Slider Height here", "10", "PieceMaker/flash/expressInstall.swf", flashvars, params, attributes);

    The code is below

    <?php

    class PMDecorator extends DataObjectDecorator{

       function extraStatics() {
          return array(
          'db' => array(
                'SliderWidth' => 'Varchar',
                'SliderHeight' => 'Varchar'
             ),
             'defaults' => array(
                'SliderWidth' => '760',
                'SliderHeight' => '300'      
             ),
             'has_many' => array(
                'PMItems' => 'PMItem',
             )
          );
       }

       public function updateCMSFields(FieldSet &$fields) {
          $Banners = new DataObjectManager(
                $this->owner,
                'PMItems',
                'PMItem',
                array(
                   "Thumbnail" => "Thumbnail",
                   'AlternateText' =>'AlternateText'
                ),
                'getCMSFields_forPopup'
          );
          $fields->addFieldToTab( 'Root.Showcase', $Banners );         
          $fields->addFieldsToTab("Root.PiecemakerSettings",array(
             new TextField('SliderWidth',_t('PieceMaker.IMAGEWIDTH',"Image Width")),
             new TextField('SliderHeight',_t('PieceMaker.IMAGEHEIGHT',"Image Height"))
          ));      
       }         
    }

    class PMDecorator_Controller extends SiteTreeDecorator {

       public function contentcontrollerInit($controller) {
          Requirements::javascript("PieceMaker/javascript/swfaddress.js");
          Requirements::javascript("PieceMaker/javascript/swfobject.js");
          
          $xmllink = $controller->Link('sliderconfig');
          Requirements::customScript('
          
        var attributes = {id:"PieceMaker-container"};

           var flashvars = {};
        flashvars.cssSource = "PieceMaker/css/piecemaker.css";
        flashvars.xmlSource = "'.$xmllink.'";

        var params = {};
        params.play = "true";
        params.menu = "false";
        params.scale = "showall";
        params.wmode = "transparent";
        params.allowfullscreen = "true";
        params.allowscriptaccess = "always";
        params.allownetworking = "all";

        swfobject.embedSWF("PieceMaker/flash/piecemaker.swf", "PieceMaker-container", "Help-needed", "Help-needed", "10", "PieceMaker/flash/expressInstall.swf", flashvars, params, attributes);
          
          ');
       }   
    }

    class PMDecorator_Extension extends Extension{
       public static $allowed_actions = array(
          'sliderconfig'
       );
       
       function sliderconfig(){
          ContentNegotiator::disable();
          $configBody = $this->owner->renderWith('Config');
          $rsp = new SS_HTTPResponse($configBody,200,'OK');
          $rsp->addHeader('Content-Type', 'application/xml; charset="utf-8"');      
          return $rsp;      
       }
    }

    class PM_ImageDecorator extends DataObjectDecorator {
       public function FullImageURL() {
          $url = $this->owner->getRelativePath();
          return Director::absoluteURL($url);   
       }
    }

  • UncleCheese
    Avatar
    4085 Posts

    Re: Help needed with DataObjectDecorator Code Link to this post

    Why not just $SliderWidth and $SliderHeight? I'm not sure I understand the problem.

    ---------------
    Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com

  • Webdoc
    Avatar
    Community Member
    332 Posts

    Re: Help needed with DataObjectDecorator Code Link to this post

    The Part where it writes the
    swfobject.embedSWF("PieceMaker/flash/piecemaker.swf", "PieceMaker-container", "Slider Width here", "Slider Height here", "10", "PieceMaker/flash/expressInstall.swf", flashvars, params, attributes);

    is inside the code not in template

    tried:
    swfobject.embedSWF("PieceMaker/flash/piecemaker.swf", "PieceMaker-container", "$SliderWidth", "$SliderHeight", "10", "PieceMaker/flash/expressInstall.swf", flashvars, params, attributes);

    But it didn work it passed the size of flash object as:
    <object id="PieceMaker-container" width="$SliderWidth" height="$SliderHeight" type="application/x-shockwave-flash" data="PieceMaker/flash/piecemaker.swf" style="visibility: visible;">

    The code part i modified was The module Piecemaker because there wasnt plase in admin where u can edit how much is the slider width and height

  • UncleCheese
    Avatar
    4085 Posts

    Re: Help needed with DataObjectDecorator Code Link to this post

    Use Requirements::customScript() and place the variables in there.

    --------------------
    SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

  • Webdoc
    Avatar
    Community Member
    332 Posts

    Re: Help needed with DataObjectDecorator Code Link to this post

    sorry im a bit newbie can u make an example or give some tutorial link how to do it
    also in pmitem part is the AlternateText thing in template i use the
    <% control PMItems %>
             <% control PMItemFile %>
                      $Top.AlternateText
             <% end_control %>
    <% end_control %>

    but it doesnt show up

  • UncleCheese
    Avatar
    4085 Posts

    Re: Help needed with DataObjectDecorator Code Link to this post

    Instead of using an external JS file, just use a custom script.

    Requirements::customScript('swfobject.embedSWF("PieceMaker/flash/piecemaker.swf", "PieceMaker-container", "'.$this->SliderWidth.'", "'.$this->SliderHeight.'", "10", "PieceMaker/flash/expressInstall.swf", flashvars, params, attributes)');

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