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.

Data Model Questions /

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

Hooking into Dev/Build


Go to End


5 Posts   2070 Views

Avatar
PhillBex

Community Member, 6 Posts

19 August 2015 at 10:13pm

Hiya

I am just in the process of creating a module and need to create a page in the site tree when dev/build is run.

I know that I can extend BuildTask to add a new task to dev/tasks but how do I hook into dev/build so that the code is run when dev/build is run?

Cheers

Phill

Avatar
swaiba

Forum Moderator, 1899 Posts

19 August 2015 at 10:30pm

Edited: 19/08/2015 10:35pm

Something like this...

class DevBuildExtension extends DevBuildController {
	private static $url_handlers = array(
		'' => 'build'
	);

	private static $allowed_actions = array(
		'build'
	);

	public function build($request) {

		//do stuff before the build
		parent::build($request);
		//do stuff after the build
	}
}

with _config.yml

DevelopmentAdmin:
  registered_controllers:
      build:
        controller: 'DevBuildExtension'

Avatar
PhillBex

Community Member, 6 Posts

19 August 2015 at 11:06pm

Thanks for the speedy reply, that worked perfectly.

Cheers

Phill

Avatar
camfindlay

Forum Moderator, 267 Posts

20 August 2015 at 11:47am

checkout the requireDefaultRecords() method. It is a method you can add to any DataObject (or descendant of a DataObject like a Page Type) to trigger some code upon a dev/build. See http://api.silverstripe.org/3.1/source-class-DataObject.html#3143-3168

Avatar
swaiba

Forum Moderator, 1899 Posts

20 August 2015 at 7:59pm

Seeing Cams response he is right, I've over complicated the issue for you! But it does allow a different ability to hook in before or after, but just to add something as part of the build definitely use requireDefaultRecords