Skip to content

Instantly share code, notes, and snippets.

View muskie9's full-sized avatar

Nic muskie9

View GitHub Profile
<?php
class MaxWidthHeightImageExtension extends DataExtension {
/**
* Crop an image if it exceeds a certain height.
* Use in templates e.g. $Image.SetWidth(200).MaxHeight(200)
*
* @param integer $maxHeight Max height of image
* @return Image
ko_KR:
Header:
LANGUAGE_LABEL: '언어'
Footer:
SITEMAP_LABEL: '사이트맵'
@muskie9
muskie9 / PhoneNumberField.php
Last active August 29, 2015 14:25 — forked from Zauberfisch/PhoneNumberField.php
Custom SilverStripe PhoneNumberField
<?php
/*
class MyDataObject extends DataObject {
private static $db = [
'FoobarCountryCode' => 'Varchar',
'FoobarAreaCode' => 'Varchar',
'FoobarPhoneNumber' => 'Varchar',
'FoobarExtension' => 'Varchar',
];
(function ($) {
var clonePriorTimes = function (button) {
var toCopy = button.attr('name');
console.log(toCopy);
};
$('.cms-edit-form .field.can-copy .ui-button').entwine({
onclick: function () {
clonePriorTimes(this);
<?php
public function getEditForm($id = null, $fields = null) {
$form = parent::getEditForm($id, $fields);
// $gridFieldName is generated from the ModelClass, eg if the Class 'Product'
// is managed by this ModelAdmin, the GridField for it will also be named 'Product'
$gridFieldName = $this->sanitiseClassName($this->modelClass);
if($gridFieldName=='Speaker'){
$gridField = $form->Fields()->fieldByName($gridFieldName);
$gridField->getConfig()->addComponent(new GridFieldOrderableRows());
jQuery(document).ready(function(){
jQuery.each('.same', function(index){
var newClass = 'extra' + index;
jQuery(this).addClass(newClass);
});
});
<?php
class MyObject extends DataObject{
private static $has_one = array(
'Image' => 'Image'
);
public function getOriginalImage(){
return $this->Image();
<?php
class MyClass extends Page{
public static function getFilteredList(SS_HTTPRequest $request = null){
//assume the request var holds a valid SS_HTTPRequest
$list = MyObject::get();
if($someVar = $request->getVar('Somevar')){
<?php
class MyPage extends Page{
}
class MyPage_Controller extends Page_Controller{
private static $allowed_actions = array();
<?php
public function validate()
{
$result = parent::validate();
if($this->MyImage()->getWidth() < 100 || $this->MyImage()->getHeight() < 100) {
$result->error('Need a larger image');
}