7921 Posts in 1359 Topics by 933 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » DOM on site frontend
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 2067 Views |
-
DOM on site frontend

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.
-
Re: DOM on site frontend

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.
-
Re: DOM on site frontend

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 http://doc.silverstripe.org/old/modules:dataobjectmanager: what parts should be changed? Happy to hear, many thanks in advance!
-
Re: DOM on site frontend

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.
-
Re: DOM on site frontend

10 February 2011 at 3:40am Last edited: 10 February 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
-
Re: DOM on site frontend

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
-
Re: DOM on site frontend

25 March 2011 at 7:52am
Sorry, no haven't got time to chase this any further...
| 2067 Views | ||
| Go to Top | Next > |


