Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Help with Custom DOM Action

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 346 Views
  • Tetragrammaton
    Avatar
    Community Member
    10 Posts

    Help with Custom DOM Action Link to this post

    I'm trying to get a custom DOM action working that sets one, and only one, of the objects in the DOM to 'current.' I feel like I've done everything correctly, and I'm not getting any errors, but the objects' property isn't changing. Any clue what I might be doing wrong? Here's the code:

    In Location (the dataobject class):

    public function customDOMActions() {
          $title = $this->Type ? "Current" : "Past";
          return new DataObjectManagerAction(
             $title,
             "InternationalPage_Controller/toggleCurrent",
             "refresh"
          );
       }
       
       public function toggleCurrent() {
          if($this->getField('Type') == 'currLoc')
             $this->setField('Type', 'pastLoc');
          else
             $this->setField('Type', 'currLoc');
          $this->write();
       }

    And in InternationalPage (the parent page):

    class InternationalPage_Controller extends Page_Controller {
       static $url_handlers = array(
          'toggleCurrent' => 'handleCurrent'
       );
       
       public function handleCurrent() {
          $locations = DataObject::get('Location');
          foreach($locations as $location) {
                $location->toggleCurrent();
          }
       }
    }

  • Tetragrammaton
    Avatar
    Community Member
    10 Posts

    Re: Help with Custom DOM Action Link to this post

    Anybody?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Help with Custom DOM Action Link to this post

    You're going to need to provide more information. What is happening with the request? Are you sure it's hitting that controller? Can you put some output in that function and check the response?

    ---------------
    Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com

  • Tetragrammaton
    Avatar
    Community Member
    10 Posts

    Re: Help with Custom DOM Action Link to this post

    I'm getting a 200 from both the GET and the POST from the controller, so I think that part is working correctly, but I'll try to throw in some sort of output into the function when I get home to see if it really is.

    Thanks for responding.

  • Tetragrammaton
    Avatar
    Community Member
    10 Posts

    Re: Help with Custom DOM Action Link to this post

    Ok, now I'm getting a status:cancelled from the controller. I haven't been able to get the controller to return any output, so I'd guess I've broken something.

    346 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.