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.

Data Model Questions

Show has_one dataobject in CMS with popup details


6 Posts   1788 Views


28 June 2010 at 2:11am Community Member, 75 Posts

I'm using dataobjects & ModelAdmin to store customers and details for a retail store.

Order has_one customer, and customer has_many orders.

When you look at the "order" tab of Modeladmin, the customer is displayed (selected by default) in a dropdown list.

Instead of this, I'd like the customers name to be displayed with the option to view their details, like in a ComplexTableField - however I ONLY want the customer who owns the current order to be displayed, not all customers. Could someone please advise (with an example code snippet) how I could achieve this?


30 June 2010 at 1:30pm Community Member, 75 Posts

Anyone with any suggestions on how I can achieve this??


2 November 2010 at 1:01am Community Member, 75 Posts

Anyone with any ideas on this one??


2 November 2010 at 2:00am (Last edited: 2 November 2010 2:01am), Forum Moderator, 1796 Posts

This will replace the filed with a read only field...

$fields->removeByName('FIELDNAME TO REMOVE');

this is what probably will take you to editing the required item, but that will be in the normal way and lose your "context" of the record you are editing... but it is untested...

$fields->insertBefore(new LiteralField('FIELDNAME LINK',"<button onClick=\"adminurl/DataObject/<id>/edit\">Edit</button>"),'FIELDNAME TOBEINSERTEDBEFORE');

This is my code that places some data from a url into a face box popup, if this helps...

<button onClick=\"jQuery.facebox(function() {jQuery.get('myurl',function(data){jQuery.facebox(data)})})\">

I use a combination of the above to allow editing of records in custom ways, while still using all of the model admin. I hope this helps and look forward to see a full solution if you get one!



2 November 2010 at 9:52am Forum Moderator, 1796 Posts

I should have mentioned the about goes in getCMSFields in the DataObject. And as it happens I grow curious for this as well, but I'll settle for being able to edit the has_one in any fashion, e.g. findOrMakeTab, fill it with the $this->HasOneObject()->getCMSFields(), but then how to add it to the save of the object under edit already? I'm going to prepare an example and hopefully, with the help of the excellent silverstripe community we can get this solved :)


19 November 2010 at 3:00am (Last edited: 19 November 2010 4:59am), Forum Moderator, 1796 Posts

Well - it's not quite the solution I was after, but this works functionally and is very simple to implement...

function getCMSFields() {
      $hasOneCTF = new HasOneComplexTableField($this,'DATAOBJECT','DATAOBJECT',null,null,'ID='.$this->DATAOBJECTID);
      $hasOneCTF->Markable = false;
      $fields->addFieldToTab("Root.DATAOBJECT", $hasOneCTF);