Jump to:

7939 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » DOM on site frontend

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 2540 Views
  • Capt. Morgan
    Avatar
    Community Member
    30 Posts

    DOM on site frontend Link to this post

    I want to use DOM on my sites frontend, but can't get to to work 100%. From Page Admin in the CMS I'm creating and managing my dataobjects perfect. But from the frontend I can't get the relations right. All my Objects shall have a has_one relation to the page where I create them from. But that is the only part I can't get to work. I see the actual Add request has a lot fewer parameters when I try running it from frontend, but didn't manage to figure out why yet. I construct the DOM field exactly the same in CMS and frontend.

          $dom = new DataObjectManager(
             $this->dataRecord,
             'MyObjects',
             'MyObject',
             array( 'Title' => 'Title' ),
             'getCMSFields_forPopup',
             'PageID = ' . $this->dataRecord->ID
          );

    If someone has any experience setting up DOM at frontend I'd be happy to hear about it.

  • Capt. Morgan
    Avatar
    Community Member
    30 Posts

    Re: DOM on site frontend Link to this post

    I'm giving up my attempts to have a pretty solution to this. The ID of the parent class isn't being set as it does when using DOM from within the CMS. I have actually not been able to figure out when the record is set in the form object..
    Anyway, here is my dirty workaround for anyone who doesn't mind sloppy code

    class MyObject extends DataObject {

    static $has_one array( 'HolderPage' => 'MyObjectHolder' );

       public function __construct( $record = null, $isSingleton = false ) {
          parent::__construct( $record, $isSingleton );

          if( $this->CurrentPage()->ClassName == 'MyObjectHolder' ) {
             $this->HolderPageID = $this->CurrentPage()->ID;
          }
       }
    }

    This will let the Form object load the hidden form fields with parentClass and parentClassID to the popup IF it's being generated from the page on the frontend site that has DOM.

  • klikhier
    Avatar
    Community Member
    150 Posts

    Re: DOM on site frontend Link to this post

    Hi Captain Morgan,

    Could you share a little more with me on how you've implemented this on the front-end? When looking at http://doc.silverstripe.org/old/modules:dataobjectmanager: what parts should be changed? Happy to hear, many thanks in advance!

  • Capt. Morgan
    Avatar
    Community Member
    30 Posts

    Re: DOM on site frontend Link to this post

    To begin with, I have not tested my solution enough as the site I'm building is still in it's cradle.

    Apart from the workaround I described in my last post I didn't do anything special to work the DOM frontend. I just instanciate a Form object where I add the DataObjectManager field. Then I'm able to save objects but the relations to the parent won't set. That's the problem I solved with the workaround described in my second post.

    What I should look into next are the permissions. Currently I just have permission checks on the form actions. But I have not yet looked into what can be done from the different ajax requests in the DOM field.

    Not sure I was of my help klilhier. If you have any more specific questions I'll gladly answer them if I can.

  • klikhier
    Avatar
    Community Member
    150 Posts

    Re: DOM on site frontend Link to this post

    Actually, I'm trying to add DOM to the ForumRole of the Forum, an extension of Member.

    DataObject:

    <?php

    // mysite/code/Job.php

    class Job extends DataObject {

       static $db = array (
    'Title' => 'Text'
       );

       static $has_one = array (
    'ForumRole' => 'ForumRole'
       );

       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('Title',_t('CMS.TITLE_REQUIRED','Titel'))
          );
       }

       // Required in SS2.4?
       function canDelete() {
          return true;
       }

    }

    class Job_Controller extends ContentController {
       
    }

    ?>

    ForumRole changes:

       function extraStatics() {
          $fields = array(
             (...)

             'has_one' => array(
                'Avatar' => 'Image'
             ),
             // ADDED FOR FORUM ROLE / DOM TEST
             'has_many' => array(
                'Jobs' => 'Job'
             ),
             'belongs_many_many' => array(
                'ModeratedForums' => 'Forum'
             ),
             'defaults' => array(
                'ForumRank' => _t('ForumRole.COMMEMBER','Community Member')
             ),
             'searchable_fields' => array(
                'Nickname' => true
             ),
             'indexes' => array(
                'Nickname' => true,
             ),
          );
          
          return $fields;
       }

    (...)

       function getForumFields($showIdentityURL = false, $addmode = false) {
    (...)

          $personalDetailsFields = new CompositeField(
             new HeaderField("PersonalDetails", _t('ForumRole.PERSONAL','Personal Details')),
             (...)
             new ConfirmedPasswordField("Password", _t('ForumRole.PASSWORD','Password')),
             new SimpleImageField('Avatar', $avatarText),
             // ADDED FOR FORUM ROLE / DOM TEST
             new DataObjectManager(
                $this,
                'Jobs',
                'Job',
                array(),
                'getCMSFields_forPopup'
             )
          );

    (...)

    Next, I receive error when accessing frontend: website.com/ForumMemberProfile/edit:

    [Notice] Undefined property: ForumRole::$ID

  • Capt. Morgan
    Avatar
    Community Member
    30 Posts

    Re: DOM on site frontend Link to this post

    The ForumRole is an estension to Member, right?

    Then you should try using $this->owner instead of $this when instanciating the DOM. $this will give you the extension which does not have an ID field.

    Hope that helps

    //Morgan

  • vancouverWill
    Avatar
    Community Member
    121 Posts

    Re: DOM on site frontend Link to this post

    you guys get any further with this?

  • klikhier
    Avatar
    Community Member
    150 Posts

    Re: DOM on site frontend Link to this post

    Sorry, no haven't got time to chase this any further...

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