Skip to content

Instantly share code, notes, and snippets.

@Zauberfisch
Zauberfisch / Silverstripe DateField advanced Datepicker
Created August 4, 2011 07:46
Silverstripe DateField jQueryUI Datepicker with advanced configs
// add this to mysite/_config.php
Object::useCustomClass('DateField_View_JQuery', 'jQueryUIDateField_View');
// mysite/code/jQueryUIDateField_View.php
class jQueryUIDateField_View extends DateField_View_JQuery {
function onBeforeRender() {
$Field = $this->getField();
$format = self::convert_iso_to_jquery_format($Field->getConfig('dateformat'));
$conf = array(
'dateFormat' => $format
<?php
class DaysSliderField extends SliderField {
function Value() {
$Day = _t("Date.DAY", "day");
$Days = _t("Date.DAYS", "days");
$AndMore = _t('TravelType.AndMore', 'and more');
$values = $this->getConfig('values');
$str = $values[0];
$str .= ($values[0] == 1)?' '.$Day:' '.$Days;
@Zauberfisch
Zauberfisch / Page.php
Created November 22, 2011 09:26
[SilverStripe] Page with Folder (always same name)
<?php
class myPage extends Page {
public static $has_one = array(
'Folder' => 'Folder'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
//$PhotoManager = new ImageDataObjectManager (/* some params here */);
@Zauberfisch
Zauberfisch / _config.php
Created November 22, 2011 19:26
[Silverstripe] Display ID and Filesize in AssetsAdmin (Works with and without DataObjectManager!)
<?php
if (class_exists('AssetManager')) DataObjectManager::allow_assets_override(false); // if DOM is installed
Object::add_extension('Folder', 'myAssetsFolderDecorator');
if (class_exists('AssetManager')) DataObjectManager::allow_assets_override(true); // if DOM is installed
@Zauberfisch
Zauberfisch / Page.php
Created December 30, 2011 12:30
[Silverstripe] add <a href="big.png"> to all <img class"popup" src="small.png"> to allow opening full image
class Page extends SiteTree {
...
function Content() {
$content = $this->Content;
// move class to the beginning right after <img
$pattern[0] = '/(<img)([^>]*?)(class=(\'|")([^>]*?)(\'|"))([^>]*?>)/i';
$replacement[0] = '$1 $3$2$7';
// add <a> to all images with class popup and a src having _resampled
@Zauberfisch
Zauberfisch / _rgba-background.scss
Created February 7, 2012 16:49
[SCSS] Cross Browser alpha background colour mixin
@mixin rgba-background($color, $opacity) {
$rgba: rgba($color, $opacity);
$IEcolor: ie_hex_str($rgba);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#{$IEcolor}', endColorstr='#{$IEcolor}', GradientType=0 );
background: $rgba;
}
@Zauberfisch
Zauberfisch / GridFieldPersonSalutationDropDown.php
Created March 3, 2013 20:51
GridField example inline/inrow Dropdown example (Changing a Persons Salutation)
<?php
class GridFieldPersonSalutationDropDown implements GridField_ColumnProvider, GridField_URLHandler {
public function augmentColumns($gridField, &$columns) {
$columns[] = 'Salutation';
}
public function getColumnsHandled($gridField) {
return array('Salutation');
}
/**
* Return children from the stage site
*
* @param showAll Inlcude all of the elements, even those not shown in the menus.
* (only applicable when extension is applied to {@link SiteTree}).
* @return SS_List
*/
public function stageChildren($showAll = false) {
$baseClass = ClassInfo::baseDataClass($this->owner->class);
@Zauberfisch
Zauberfisch / gist:6992149
Created October 15, 2013 14:08
Hack for IntelliJ SCSS/Compass FileWatcher. FileWather uses scss by default (/usr/bin/scss on mac), so to get it to compile to compass one can replace scss with the following code:
require 'rubygems'
version = ">= 0"
ARGV.clear
ARGV << "compile"
path = ".."
i = 0
while !File.exists?(File.join(path, "config.rb"))
if i > 3 then
@Zauberfisch
Zauberfisch / MyModelAdmin.php
Created October 24, 2013 08:55
Hide ModelAdmin sidebar in SilverStripe 3.x
<?php
class MyModelAdmin extends ModelAdmin {
private static $managed_models = array('MyDataObject');
private static $url_segment = 'foobar';
}