Skip to content

Instantly share code, notes, and snippets.

@stojg
Last active December 15, 2015 09:49
Show Gist options
  • Save stojg/5240804 to your computer and use it in GitHub Desktop.
Save stojg/5240804 to your computer and use it in GitHub Desktop.
This is an example of using the siteconfig decorator for adding a sitewide quicklinks navigation
<?php
Object::add_extension('SiteConfig', 'QuickLinksSiteConfig');
<ul class="inline-block">
<% loop SiteConfig.QuickLinks %>
<li><a href="$Link" <% if OnClick %>onclick="$OnClick.XML" <% end_if %><% if AccessKey %>accesskey="$AccessKey.XML" <% end_if %>alt="$AltText.XML" class="arrow">$Title</a></li>
<% end_loop %>
</ul>
<?php
/**
* Adds fields to the global settings
*
* @package SiteConfig
*/
class QuickLinksSiteConfig extends DataExtension {
/**
* Extra static fields to add to the SiteConfig object
*
* @var Array
*/
public static $has_many = array(
'QuickLinks' => 'QuickLink'
);
/**
* Adds form fields to the CMS settings page for each of the extra static fields
*
* @param FieldList $fields The list of fields defined in the parent class SiteConfig
*/
public function updateCMSFields(FieldList $fields) {
$config = new GridFieldConfig();
$config->addComponent(new GridFieldToolbarHeader());
$config->addComponent($sort = new GridFieldSortableHeader());
$config->addComponent(new GridFieldInlineEditing());
$config->addComponent(new GridFieldButtonRow('before'));
$config->addComponent($addButton = new GridFieldAddNewButton('buttons-before-left'));
$addButton->setButtonName('Add quicklink');
$config->addComponent(new GridFieldDeleteAction());
$config->addComponent(new GridFieldEditButton());
$config->addComponent(new GridFieldDetailForm());
$config->addComponent(new GridFieldSortableRows('Order'));
$gridField = new GridField('Quicklink', 'QuickLinks', $this->owner->QuickLinks(), $config);
$fields->addFieldToTab('Root.QuickLinks', $gridField);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment