Skip to content

Instantly share code, notes, and snippets.

@adrexia
adrexia / closetabs.js
Created November 29, 2012 03:24
Close tabs when something else is clicked
var that = this;
var closeHandler = function(event){
if (!$(event.target).closest(that).length) {
that.tabs('option', 'active', false);
var frame = $('.cms').find('iframe');
frame.each(function(index, iframe){
$(iframe).contents().off('click', closeHandler);
});
$(document).off('click', closeHandler);
};
@adrexia
adrexia / ListboxField.php
Last active December 16, 2015 22:19
Replace taxonomy GridField with ListboxField
$fields->removeByName("Tags");
$taxonomyMap = TaxonomyTerm::get()->map("ID", "Name")->toArray();
asort($taxonomyMap);
$taxonomy = ListboxField::create('Terms', singleton('TaxonomyTerm')->i18n_plural_name())
->setMultiple(true)
->setSource($taxonomyMap)
->setAttribute(
'data-placeholder',
_t('Member.Tags', 'Tags', 'Placeholder text for a dropdown'));
@adrexia
adrexia / SwitchField.md
Last active August 29, 2015 13:59
A switch field for use in Silverstripe

SwitchField.php

<?php
/**
 * Field to render a checkbox as a switch with left and right option text.
 */
class SwitchField extends CompositeField {

  public function __construct($checkboxField, $leftOption, $rightOption) {
@adrexia
adrexia / styles.less
Last active December 14, 2016 15:45
Atom - hide file icons and replace arrows
.tree-view {
.icon:before{
display:none;
}
&.list-tree.has-collapsable-children .list-nested-item {
> .list-item:before{
content: "\f05b";
}
&.collapsed > .list-item:before{
content: "\f05a";
@adrexia
adrexia / manymany.php
Created June 18, 2014 04:32
Silverstripe - Manually add Many Many Relations
public function setManyManyRelation($relationFieldList){
if(!$relationFieldList){
return false;
}
foreach($relationFieldList as $relation){
$this->ManyManyRelation()->add($relation);
}
}
$result = new ArrayList();
foreach($dataList as $dataListItem) {
$result->push(new ArrayData(array(
'Title' => $Title,
'Othervalue' => $something
)));
}
return $result;
public function updateCMSFields(FieldList $fields) {
// Make sure settings tab is last
$formContent = $fields->fieldByName('Root.Settings');
$fields->removeByName('Settings');
$fields->findOrMakeTab('Root.Settings', $formContent);
}
@adrexia
adrexia / SplitList.md
Last active August 29, 2015 14:04
Silverstripe - Divide an SS_List object into groups of x items

Divide an SS_List object into groups of x items

::PHP (on page, or controller, or whatever the object is that has the relation to the list)

	/**
	 * Method to divide data into columns.
	 * @return array
	 */
	public function splitIntoCols() {
@adrexia
adrexia / Custom_template.md
Last active August 29, 2015 14:04
Custom templates on Page_Controller to work with userforms
private static $allowed_actions = array (
	'expandPageContent' 
);


/*
 * Method to retrive the rendered page template, sans any external elements (such as header, footer, nav)
 * 
 * @return HTMLText

*/

@adrexia
adrexia / SplitList.php
Last active July 13, 2017 14:22
Silverstripe: A list decorator that allows a list to be grouped into sub-lists by number
<?php
/**
* A list decorator that allows a list to be grouped into sub-lists by number. Based on GroupBy functionality
* @author Naomi Guyer
*/
class SplitList extends SS_ListDecorator {
/**
* @param string $num
* @return array