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

Help with Custom DOM Action


Go to End


5 Posts   926 Views

Avatar
Tetragrammaton

Community Member, 10 Posts

21 November 2011 at 1:36pm

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();
		}
	}
}

Avatar
Tetragrammaton

Community Member, 10 Posts

21 November 2011 at 11:24pm

Anybody?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

24 November 2011 at 4:20pm

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

Avatar
Tetragrammaton

Community Member, 10 Posts

24 November 2011 at 6:31pm

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.

Avatar
Tetragrammaton

Community Member, 10 Posts

28 November 2011 at 11:39am

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.