Skip to content

Instantly share code, notes, and snippets.

@kinglozzer
kinglozzer / RequestHandler.php
Created March 4, 2013 12:22
Lines 66 - 74 amended. Causes "[User Warning] popCurrent called on ModelAsController controller, but it wasn't at the top of the stack" and "[User Warning] Couldn't set response type to 404 because of output on line 101 of /Users/lawrence/Devsites/abelhomes/framework/dev/DebugView.php" on sites that are in dev mode.
<?php
/**
* Handles URL requests.
*
* - ViewableData::handleRequest() iterates through each rule in {@link self::$url_handlers}.
* - If the rule matches, the named method will be called.
* - If there is still more URL to be processed, then handleRequest()
* is called on the object that that method returns.
*
/**
* File: NewsPage.js
*/
(function($) {
$.entwine('ss', function($) {
/**
* Class: .cms-edit-form .Actions #Form_EditForm_action_deletefromlive
*
* Show users a warning before allowing them to delete a page of 'NewsPage'
* page type.
<?php
class Plot extends DataObject {
public static $db = array(
'SortOrder' => 'Int',
'Title' => 'Varchar',
'Availability' => "Enum('Available, Reserved, Sold')",
'Price' => 'Currency',
'SalePrice' => 'Currency',
@kinglozzer
kinglozzer / gist:5848538
Created June 24, 2013 08:20
'No alignment' option for images. Only tested on 3.0, though I imagine it would work on 3.1 fine. Apply with Object::add_extension('HtmlEditorField_Toolbar', 'HtmlEditorField_ToolbarExtension');
<?php
/**
* Add 'no alignment' option when inserting images through 'Insert Media' form
*/
class HtmlEditorField_ToolbarExtension extends Extension {
public function updateFieldsForImage(&$fields, $url, $file) {
$className = $fields->fieldByName('CSSClass');
$classes = $className->getSource();
$classes = array_merge(array('' => _t('HtmlEditorField.CSSCLASSNONE', 'No alignment.')), $classes);
<?php
private static $image_alignment_options = null;
//....
new TextField('CaptionText', _t('HtmlEditorField.CAPTIONTEXT', 'Caption text')),
DropdownField::create(
'CSSClass',
_t('HtmlEditorField.CSSCLASS', 'Alignment / style'),
$this->getImageAlignmentOptions()
)->addExtraClass('last')
@kinglozzer
kinglozzer / LinkSwitcher.js
Last active March 8, 2016 12:31
SilverStripe page/file/external URL field setup
/**
* File: LinkSwitcher.js
*/
(function($) {
$.entwine(function($) {
/**
* Class: .cms-edit-form .field.switchable-controller
*/
$('.cms-edit-form .field.switchable-controller').entwine({
<?php
class CustomGDBackend extends GDBackend {
public function watermark() {
$newGD = imagecreatetruecolor($width, $height);
// Do image watermark stuff here. The current image resource is $this->gd
imagecopyresampled($newGD, $this->gd, 0, 0, $left, $top, $width, $height, $width, $height);
<?php
if ($data['Tel'] !== $data['ConfirmTel']) {
Session::set("FormInfo.{$form->FormName()}.data", $form->getData());
$form->addErrorMessage('Tel', 'Telephone numbers do not match', 'message required');
return $this->redirectBack();
}
<?php
public function index() {
// If they've not seen the intro, show that and set the cookie...
if ( ! Cookie::get('ShownIntro')) {
Cookie::set('ShownIntro', true);
return $this->renderWith(array('IntroPage', 'Page'));
}
// ... otherwise proceed as normal
<ul><!--
--><% loop Menu(1) %><!--
--><li class="$LinkingMode"><!--
--><a href="$Link">$MenuTitle.XML</a><!--
--></li><!--
--><% end_loop %><!--
--></ul>