Made a Silverstripe 3 compatible version by pulling together changes in other forks.

Tested with 3.1 beta only