Skip to content

Instantly share code, notes, and snippets.

@adrexia
adrexia / viewobject.php
Created May 13, 2020 12:16
Merge a ViewObject or a ArrayDataObject with a DataList
$list = SomeObject::get()->toArray();
$singleViewObject = SingleViewObject::create([
'Title' => 'Hello World'
]);
$result = array_merge($list, [$singleViewObject]);
return ArrayList::create($result);
<?php
namespace App\Extensions;
class BaseElementExtension extends Extension
{
/**
* Flag to indiciate if this element is a new element. Used because isChanged('ID') seems to be unreliable
*
* @var bool
@adrexia
adrexia / EditorConfig.php
Last active July 15, 2020 22:27
Set up various TinyMCE Editors
<?php
namespace App\Config;
use SilverStripe\Core\Manifest\ModuleLoader;
use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;
class EditorConfig
{
public static function setAllEditors()
$editor = HtmlEditorConfig::get('cms');
// Enable template plugin in the WYSIWYG editor//
$editor->enablePlugins('template');
$editor->insertButtonsAfter('tablecontrols', 'template');
//Specify location of your snippets//
$editor->setOptions(['template_templates'=> [
[
'title'=>'Quote - Text Color',
<?php
class MyDataObject extends DataObject implements PermissionProvider {
public function canView($member = NULL, $context = []) {
return Permission::check('MYOBJECT_VIEW');
}
public function canEdit($member = NULL, $context = []) {
return Permission::check('MYOBJECT_EDIT');
}
<?php
private static $has_one = array(
'ImagePath' => 'Folder'
);
// in settings
$fields->insertBefore(
new TreeDropdownField(
### 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 / gist:8d6d598cb67f245002fd
Last active March 5, 2020 03:29
Member listbox
$memberMap = Member::get()->map("ID", "FirstName")->toArray();
asort($memberMap);
$memberMap = ListboxField::create('Collaborators', singleton('Member')->i18n_plural_name())
->setMultiple(true)
->setSource($memberMap)
->setAttribute(
'data-placeholder',
'Collaborators'
);
<?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. */
@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