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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

DataObjectManager usage in frontend form


Go to End


3 Posts   2132 Views

Avatar
Andre

Community Member, 146 Posts

4 March 2011 at 8:54am

Hi there, I'm trying to add the DOM functionality to a Frontend Form.

I want to give the logged in User to add some resources that belong to him.

The Resources are simple Dataobjects (in my case Customers, with Name, Address and Description).

Let me show you some code:

// The Member Decorator
class Account extends DataObjectDecorator {
    public function extraStatics() {
	return array(
            'has_many' => array(
                'Customers' => 'Customer'
            )
        );
    }
    public function getCustomers(){
        return $this->owner->Customers();
    }
}

// the customer
class Customer extends DataObject {
    static $db = array(
        'Name' => 'Varchar',
        'Address' => 'Text',
        'Description' => 'Text'
    );
    static $has_one = array(
        'Account' => 'Member'
    );
    function getCustomerFields_forPopup(){
        return new FieldSet(
                new TextField('Name'),
                new TextareaField('Address'),
                new TextareaField('Description')
        );
    }
}

// the Page Object with the Form
class CustomersPage extends Page {
 }

 class CustomersPage_Controller extends Page_Controller {

        function init(){
            parent::init();
        }

        function CustomersForm(){
            
            $Manager = new DataObjectManager(
                    $this,
                    'Customers',
                    'Customer',
                    array('Name' => 'Name'),
                    'getCustomerFields_forPopup',
                    'AccountID='.Member::currentUserID()
            );
            $Manager->setParentClass('Member');
            
            $fields = new FieldSet($Manager);
            
            return new Form($this, 'CustomersForm', $fields, new FieldSet());
        }
    }

So what happens:
When I open the CustomersPage, I can see the DOM. When Pressing on "Add Customer" not the Popup comes up, but a new site opens with the form that should normaly pop up. Sure, I can add Members there, but they are not associated with the current logged in Member. Instead AccountID shows 0.

So my Question is, what do I have to do, to associate the saved Customer with the Current logged in Member ID and how can I receive the normal DOM behaviour like in the Backend Area with a popping up greybox or facebox or whatever DOM is using?

greetings

andre

Avatar
Andre

Community Member, 146 Posts

17 March 2011 at 5:05am

Hi, I know it's been a while since opening of this thread, but I will try to wake it up again in hope, some may have an idea now, how to solve this Problem.

Regrads

Andre

Avatar
fool

Community Member, 4 Posts

5 April 2011 at 8:21pm

Hi Andre,

why your Add action opens in another window, I don't know, in my case it just happens as expected. As to why the new record does not get associated with the CurrentMember, I just hit the same problem... The solution was a call to setSourceID() as follows:

$Manager->setSourceID(Member::currentUserID());

HTH, cheers,

f.