PHP code example of pixelpoems / silverstripe-selection-field
1. Go to this page and download the library: Download pixelpoems/silverstripe-selection-field library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pixelpoems / silverstripe-selection-field example snippets
private static $db = [
'Alignment' => 'Varchar',
];
private static $defaults = [
'Alignment' => 'left',
];
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldsToTab('Root.Main', [
SelectionField::create(
$name = 'Alignment',
$title = 'Alignment',
$source = [
'left' => [
'Value' => 'left',
'Title' => _t('LayoutOptions.Left', "Left"),
'ShowTitle' => true,
'Icon' => 'align-left'
],
'center' => [
'Value' => 'center',
'Title' => _t('LayoutOptions.Center', "Center"),
'ShowTitle' => true,
'Icon' => 'align-center'
],
'right' => [
'Value' => 'right',
'Title' => _t('LayoutOptions.Right', "Right"),
'ShowTitle' => true,
'Icon' => 'align-right'
],
$value = 'left'
);
]);
}
'medium' => [
'Value' => 'medium',
'Title' => _t('LayoutOptions.Medium', 'Medium'),
'ShowTitle' => true,
'Content' => 'M',
'ImgLink' => '/assets/medium.png'
],
private static array $db = [
'IconID' => 'Varchar'
];
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldsToTab('Root.Main', [
SelectionField::create('IconID', 'Icon', IconSelectionService::getIconOptions())
]);
return $fields;
}