SilverStripe module which provide a Icon
DataObject and a Settings->Appearance->Icons
Menu for managing your website's Icons.
- Stephen Corwin - [email protected]
- SilverStripe 3.1
- stephenjcorwin/silverstripe-colors
- stephenjcorwin/silverstripe-opacities
- stephenjcorwin/silverstripe-text
- Create and maintain sitewide
Icons
Installation can be done either by composer or by manually downloading a release.
####Via Composer:
composer require stephenjcorwin/silverstripe-icons
####Manually:
- Download the module from the releases page
- Extract the file
- Make sure the folder after being extracted is name
silverstripe-icons
- Place this directory in your site's root directory
####Configuration:
- After installation, make sure you rebuild your database through
dev/build
- You should see the a new Menu in the CMS for managing
Icons
available through the MenuSettings->Appearance->Icons
####Via Composer:
composer remove stephenjcorwin/silverstripe-icons
####Manually:
- Remove the
silverstripe-icons
directory in your site's root directory
####Configuration:
- After uninstalling, make sure you rebuild your database through
dev/build
####Defining a has_one
relationship with Icon
:
####mysite/code/MyDataObject.php
<?php
class MyDataObject extends DataObject {
private static $has_one = array (
'MyIcon' => 'Icon'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
/*
* MAIN TAB
*/
$tab = 'Root.Main';
//provides listbox field menu for selecting a predefined Icon
$data = DataObject::get('Icon');
$field = new ListboxField('MyIconID', 'My Icon');
$field->setSource($data->map('ID', 'Name')->toArray());
$field->setEmptyString('Select one');
$fields->addFieldToTab($tab, $field);
return $fields;
}
}
####Using the Icon in your templates:
####mysite/code/Page.php
<?php
class Page extends SiteTree {
private static $has_one = array(
'MyIcon' => 'Icon'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
/*
* MAIN TAB
*/
$tab = 'Root.Main';
//provides listbox field menu for selecting a predefined Icon
$data = DataObject::get('Icon');
$field = new ListboxField('MyIconID', 'My Icon');
$field->setSource($data->map('ID', 'Name')->toArray());
$field->setEmptyString('Select one');
$fields->addFieldToTab($tab, $field);
return $fields;
}
}
class Page_Controller extends ContentController {
public function init() {
parent::init();
}
}
####themes/mytheme/templates/Page.ss
<% if $MyIcon %>
<% with $MyIcon %><% include Icon %><% end_with %>
<% end_if %>
$Layout