Jump to:

5541 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » How to get the current action for ComplexTableField popup

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

Page: 1
Go to End
Author Topic: 1047 Views
  • santiago
    Avatar
    Community Member
    2 Posts

    How to get the current action for ComplexTableField popup Link to this post

    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

  • santiago
    Avatar
    Community Member
    2 Posts

    Re: How to get the current action for ComplexTableField popup Link to this post

    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

    1047 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.