Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Using DataObjectManager inside a DataObject Decorator

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: 1834 Views
  • dospuntocero
    Avatar
    Community Member
    54 Posts

    Using DataObjectManager inside a DataObject Decorator Link to this post

    Hi guys i was wondering why i can't use DataObjectManager inside a DataObjectDecorator... or why ComplexTableField works and DOM throws errors my code is fairly simple i think

    I'm using decorators for my HomePage class so I can control stuff that are in all pages using in templates <% control Page(home) %> stuff.

    in my _config:    DataObject::add_extension('HomePage', 'LogoDecorator');

    <?php

    class LogoDecorator extends DataObjectDecorator{

       function extraStatics() {
          return array(
             'has_many' => array(
                'Logos' => 'Logo',
             ),
          );
       }

       public function updateCMSFields(FieldSet &$fields) {
          $Banners = new ComplexTableField(
                $this,
                'Logos',
                'Logo',
                array(
                   'TextoAlternativo' =>'TextoAlternativo',
                   'Link' =>'Link'
                ),
                'getCMSFields_forPopup'
          );
          $Banners->setParentClass('HomePage');   
          $fields->addFieldToTab( 'Root.Content.Logos', $Banners );      
       }   
    }

    and my logo class:

    <?php

    class Logo extends DataObject {

       static $db = array (
          'TextoAlternativo' => 'Varchar(140)',
          'Link' => 'Varchar(255)'
       );
       
       static $has_one = array (
          'HomePage' => 'HomePage',
          'Logo' => 'Image'
       );      
       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextareaField('TextoAlternativo', 'Texto Alternativo (para google) - máximo 140 caracteres'),
             new TextField("Link", "URL de la página de logo (sin http://)"),
             new ImageField('Logo', 'Agregar imagen para el banner')
          );
       }   
    }

    when i use DOM instead of ComplexTableField, the code just stop working... any clues?

    thanks for all guys!

  • UncleCheese
    Avatar
    4085 Posts

    Re: Using DataObjectManager inside a DataObject Decorator Link to this post

    What does "stops working" mean? It's hard to troubleshoot something if you're not explaining the result.

  • dospuntocero
    Avatar
    Community Member
    54 Posts

    Re: Using DataObjectManager inside a DataObject Decorator Link to this post

    well the error is a little bit large...

    La página en http://sta dice:ERROR [Notice]: Undefined property: LogoDecorator::$ID
    IN POST /admin/getitem?ID=5&ajax=1
    Line 211 in /Users/francisco/Sites/stachile/dataobject_manager/code/DataObjectManager.php

    Source
    ======
    202:       $sort     = isset($params['sort'])? $params['sort']        :    $this->sort;
    203:       $sort_dir = isset($params['sort_dir'])? $params['sort_dir'] :    $this->sort_dir;
    204:       $filter = isset($params['filter'])? $params['filter']     :    $this->filter;
    205:       $search = isset($params['search'])? $params['search']     :    $this->search;
    206:       return
    "ctf[{$this->Name()}][start]={$start}&ctf[{$this->Name()}][per_page]={$per_page}&ctf[{$this->Name()}][showall]={$show_all}&ctf[{$this->Name()}][sort]={$sort}&ctf[{$this->Name()}][sort_dir]={$sort_dir}&ctf[{$this->Name()}][search]={$search}&ctf[{$this->Name()}][filter]={$filter}";
    207:    }
    208:    
    209:    function FieldHolder()
    210:    {
    * 211:       if(!$this->controller->ID && $this->isNested)
    212:          return $this->renderWith('DataObjectManager_holder');
    213:       return parent::FieldHolder();
    214:    }
    215:
    216:    
    217:    public function Headings()

    <ul>DataObjectManager->FieldHolder()

    call_user_func_array(Array,Array)
    line 408 of ViewableData.php

    ViewableData->XML_val(FieldHolder,,1)
    line 74 of .cache.Users.francisco.Sites.stachile.sapphire.templates.TabSetFieldHolder.ss

    include(/private/var/tmp/silverstripe-cache-Users-francisco-Sites-stachile/.cache.Users.francisco.Sites.stachile.sapphire.templates.TabSetFieldHolder.ss)
    line 354 of SSViewer.php

    SSViewer->process(TabSet)
    line 773 of ViewableData.php

    ViewableData->renderWith(TabSetFieldHolder)
    line 62 of TabSet.php

    TabSet->FieldHolder()

    call_user_func_array(Array,Array)
    line 408 of ViewableData.php

    ViewableData->XML_val(FieldHolder,,1)
    line 59 of .cache.Users.francisco.Sites.stachile.sapphire.templates.TabSetFieldHolder.ss

    include(/private/var/tmp/silverstripe-cache-Users-francisco-Sites-stachile/.cache.Users.francisco.Sites.stachile.sapphire.templates.TabSetFieldHolder.ss)
    line 354 of SSViewer.php

    SSViewer->process(TabSet)
    line 773 of ViewableData.php

    ViewableData->renderWith(TabSetFieldHolder)
    line 62 of TabSet.php

    TabSet->FieldHolder()

    call_user_func_array(Array,Array)
    line 408 of ViewableData.php

    ViewableData->XML_val(FieldHolder,,1)
    line 70 of .cache.Users.francisco.Sites.stachile.sapphire.templates.Includes.Form.ss

    include(/private/var/tmp/silverstripe-cache-Users-francisco-Sites-stachile/.cache.Users.francisco.Sites.stachile.sapphire.templates.Includes.Form.ss)
    line 354 of SSViewer.php

    SSViewer->process(Form)
    line 773 of ViewableData.php

    ViewableData->renderWith(Array)
    line 982 of Form.php

    Form->forTemplate()
    line 1005 of Form.php

    Form->formHtmlContent()
    line 381 of LeftAndMain.php

    LeftAndMain->getitem(HTTPRequest)
    line 162 of Controller.php

    Controller->handleAction(HTTPRequest)
    line 129 of RequestHandler.php

    RequestHandler->handleRequest(HTTPRequest)
    line 122 of Controller.php

    Controller->handleRequest(HTTPRequest)
    line 277 of Director.php

    Director::handleRequest(HTTPRequest,Session)
    line 121 of Director.php

    Director::direct(/admin/getitem)
    line 118 of main.php

    </ul>

  • UncleCheese
    Avatar
    4085 Posts

    Re: Using DataObjectManager inside a DataObject Decorator Link to this post

    You're passing $this as the controller, which is the decorator. The controller you want is $this->owner.

  • dospuntocero
    Avatar
    Community Member
    54 Posts

    Re: Using DataObjectManager inside a DataObject Decorator Link to this post

    woohooo!!

    thanks UncleCheese!! now is working perfectly

    :D:D

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