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.

Customising the CMS /

How to get the current action for ComplexTableField popup


Reply


2 Posts   1082 Views

Avatar
santiago

Community Member, 2 Posts

27 May 2010 at 7:15am

Edited: 27/05/2010 7:17am

Hey,
I'm trying to find out if there is a way in which you can check whether the popup opened from a ComplexTableField is on editing/viewing (magnyfing glass icon or notebook icon being clicked) or adding mode (add new DataObject button).
The DataObject created is associated with the current admin user logged in only when creating a new DataObject. When editing, the member must be selectable through a dropdown (of course, viewing will just show the Member as readonly).

What I need in my DataObject is something like this:

function getCMSFields_forPopup() {
   $members = DataObject::get("Member") ;
   $loggedInMember = Member::currentUser();
   if($addMode){
      $memberID = $loggedInMember->ID;
   }else{
      $memberID = $this->MemberID;
   }
   return new FieldSet(
      new DropdownField( "MemberID", "Creator", $members->toDropdownMap("ID", "Name"), $memberID, null, 'Select Member' )
   );

}


replacing $addMode for whatever it suits to check the mode.

I'm using 2.4.

Any help will be much appreciated! Thanks in advance!
Santiago

Avatar
santiago

Community Member, 2 Posts

27 May 2010 at 7:41am

Ok, after posting I realize that I only need to check if the MemberID on the current DataObject is present, that will mean that is editing or viewing. Zero or not present will mean that is adding a new DataObject. So the above code will be:

function getCMSFields_forPopup() {
$members = DataObject::get("Member") ;
$loggedInMember = Member::currentUser();
if($this->MemberID>0){
$memberID = $this->MemberID;
}else{
$memberID = $loggedInMember->ID;
}
return new FieldSet(
new DropdownField( "MemberID", "Creator", $members->toDropdownMap("ID", "Name"), $memberID, null, 'Select Member' )
);

}


Anyway, the question still remains valid, as I really would like to know if there is a way to tell if there the dataobject is being edited or added.

Thanks!
Santiago