Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

DOM on site frontend


Go to End
Reply


16 Posts   2704 Views

Avatar
Capt. Morgan

Community Member, 30 Posts

31 January 2011 at 8:43am

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.

Avatar
Capt. Morgan

Community Member, 30 Posts

2 February 2011 at 10:31am

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.

Avatar
klikhier

Community Member, 150 Posts

9 February 2011 at 2:47am

Hi Captain Morgan,

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

Avatar
Capt. Morgan

Community Member, 30 Posts

9 February 2011 at 5:41am

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.

Avatar
klikhier

Community Member, 150 Posts

10 February 2011 at 3:40am

Edited: 10/02/2011 3:45am

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

Avatar
Capt. Morgan

Community Member, 30 Posts

10 February 2011 at 5:39am

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

Avatar
vancouverWill

Community Member, 121 Posts

24 March 2011 at 11:49am

you guys get any further with this?

Avatar
klikhier

Community Member, 150 Posts

25 March 2011 at 7:52am

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

Go to Top