Skip to content

Instantly share code, notes, and snippets.

@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 / 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;
@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

*/

<?php
/* What kind of environment is this: development, test, or live (ie, production)? */
define('SS_ENVIRONMENT_TYPE', 'dev');
/* Database connection */
define('SS_DATABASE_SERVER', '127.0.0.1');
define('SS_DATABASE_USERNAME', 'root');
define('SS_DATABASE_PASSWORD', '');
/* Configure a default username and password to access the CMS on all sites in this environment. */
### SILVERSTRIPE START ###
<Files *.ss>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>
<Files web.config>
Order deny,allow
Deny from all
@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 / 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";