PHP code example of goldfinch / fielder

1. Go to this page and download the library: Download goldfinch/fielder 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/ */

    

goldfinch / fielder example snippets


use SilverStripe\ORM\DataObject;

MyAwesomeModel extends DataObject
{
    public function getCMSFields()
    {
        $fields = parent::getSettingsFields()->initFielder($this);
        
        $fielder = $fields->getFielder();

        $fielder->remove('Content');

        $fielder->  'Root.Demo' => [
                $fielder->string('Headline'),
            ],
        ]);

        return $fields;
    }
}

use SilverStripe\CMS\Model\SiteTree;

MyAwesomePage extends SiteTree
{
    public function getSettingsFields()
    {
        $fields = parent::getSettingsFields()->initFielder($this);

        $fielder = $fields->getFielder();
        
        $fielder->remove('ShowInMenus');

        return $fields;
    }
}

use SilverStripe\ORM\DataObject;

MyAwesomeModel extends DataObject
{
    public function getCMSFields()
    {
        $fields = parent::getSettingsFields()->initFielder($this);
        
        $fielder = $fields->getFielder();
        
        // fielder validation
        $fielder->validate([
            'Email' => '

use SilverStripe\ORM\DataExtension;

class MyExtension extends DataExtension
{
    public function updateCMSFields($fields)
    {
        $fields->initFielder($this->owner);

        $fielder = $fields->getFielder();

        $fielder->validate([
            'Email' => '

$fielder->fields([
  'Root.Main' => [
    $fielder->string('Title'),
  ],
])

$fielder->freshFields([
  'Root.Main' => [
    $fielder->string('Title'),
  ],
])

$fielder->insertAfter('MenuTitle', $fielder->string('Title'));

$fielder->insertAfter('MenuTitle', [
    $fielder->string('Title'),
    $fielder->text('Content'),
]);

$fielder->insertBefore('MenuTitle', $fielder->string('Title'));

$fielder->insertBefore('MenuTitle', [
    $fielder->string('Title'),
    $fielder->text('Content'),
]);

$fielder->reorder(['Content', 'MenuTitle']);

$fielder->reorderTabs([
    'Root.Demo',
    'Root.Main'
]);

$fielder->toTab('Root.Demo', [
    $fielder->string('Title'),
    $fielder->text('Content'),
]);

$fielder->dataField('Title');

$fielder->field('Title');

$fielder->> validate method (recommended)

$fielder->validate([
    'Title' => '

$fielder->remove('Title');

$fielder->removeAll();

$fielder->removeAllCurrent();

$fielder->removeFieldsInTab('Root.Main');
// same as
$fielder->clearTab('Root.Main');

$fielder->description('Title', 'Some field description flies here');
// ..
$fielder->description([
    'Title' => 'Some field description flies here',
    'URLSegment' => '<strong style="color: red">Red field description</strong>'
]);

$fielder->disable('Title');
$fielder->disable('Title', false); // undisabled
// ..
$fielder->disable(['Title', 'Text']);
$fielder->disable(['Title', 'Text'], false); // undisabled all

$fielder->readonly('Title');
$fielder->readonly('Title', false); // take off readonly
// ..
$fielder->readonly(['Title', 'Text']);
$fielder->readonly(['Title', 'Text'], false); // take off readonly

$fielder->addError('Error message'); // error | ielder->addError('Error message', 'warning');
$fielder->addError('Error message', 'message');
$fielder->addError('<strong>Error</strong> message', 'good', null, 'html');

$fielder->validate([
    'Title' => function($value, $fail) {
        $max = 100;
        if (strlen($value) > $max) {
            $fail('The :attribute must not be over ' . $max . ' characters.');
        }
    }
]);

use Goldfinch\Illuminate\Rule;

$fielder->validate([
    'Title' => 'in(['apple', 'orange', 'kiwi'])],
]);

use App\Rules\PhoneRule;

$fielder->validate([
    'Phone' => ['

$fielder->displayIf();
$fielder->displayUnless();
$fielder->hideIf();
$fielder->hideUnless();

$fielder->toTab('Root.Demo', [
    $fielder->checkbox('ConditionalField'),
    $fielder->displayIf('ConditionalField', [ // isChecked
    // $fielder->displayIf('!Magic', [ // isNotChecked
    // $fielder->displayIf(['MagicString', '==', null], [ // isEmpty
    // $fielder->displayIf(['MagicString', '!=', null], [ // isNotEmpty
    // $fielder->displayIf(['MagicString', '==', 3], [ // isEqualTo
    // $fielder->displayIf(['MagicString', '==', [2,3]], [ // isEqualTo
    // $fielder->displayIf(['MagicString', '!=', 3], [ // isNotEqualTo
    // $fielder->displayIf(['MagicString', '!=', [2,3]], [ // isNotEqualTo
    // $fielder->displayIf(['MagicString', '>', 3], [ // isGreaterThan
    // $fielder->displayIf(['MagicString', '<', 3], [ // isLessThan
        $fielder->string('Field1'),
        $fielder->string('Field2'),
        $fielder->string('Field3'),
    ])
]);

$fielder->checkbox($name, $title = null, $value = null)

// left aligned checkbox (wrapped in composite field)
$fielder->lineCheckbox($name, $title = null, $value = null)

$fielder->dropdown($name, $title = null, $source = [], $value = null)

$fielder->readonlyField($name, $title = null, $value = null)

$fielder->text($name, $title = null, $value = null)

$fielder->string($name, $title = null, $value = '', $maxLength = null, $form = null)

$fielder->password($name, $title = null, $value = '')

$fielder->action($action, $title = '', $form = null)

$fielder->passwordConfirmed($name, $title = null, $value = '', $form = null, $showOnClick = false, $titleConfirmField = null)

$fielder->currency($name, $title = null, $value = '', $maxLength = null, $form = null)

$fielder->date($name, $title = null, $value = '', $maxLength = null, $form = null)

$fielder->datetime($name, $title = null, $value = '', $maxLength = null, $form = null)

$fielder->email($name, $title = null, $value = '', $maxLength = null, $form = null)

$fielder-> groupedDropdown($name, $title = null, $source = [], $value = null)
// ..
$fielder->groupedDropdown('Name', 'Title', [
    'numbers' => [1 => 1, 2 => 2],
    'letters' => [1 => 'A', 2 => 'B'],
])
// $source = FooBar::get()->map()

$fielder->html($name, $title = null, $value = '', $config = null)

$fielder->money($name, $title = null, $value = '')

$fielder->numeric($name, $title = null, $value = '', $maxLength = null, $form = null)

$fielder->radio($name, $title = null, $source = [], $value = null)
// ..
$fielder->radio('Name', 'Title', [1 => 'Option 1', 2 => 'Option 2'])
// $source = FooBar::get()->map()

$fielder->selectionGroup($name, $items, $value = null)
// ..
$fielder->selectionGroup('Name', [
    $fielder->selectionGroupItem(
        'one',
        $fielder->literal('one', 'one view'),
        'one title'
    ),
    $fielder->selectionGroupItem(
        'two',
        $fielder->literal('two', 'two view'),
        'two title'
    ),
])

$fielder->time($name, $title = null, $value = '', $maxLength = null, $form = null)

$fielder->composite($children = null)
// ..
$fielder->composite([
    $fielder->string('Title'),
    $fielder->html('Text'),
])

$fielder->group($titleOrField = null, ...$otherFields)
// ..
$fielder->group(
    'Group name',
    $fielder->string('Title'),
    $fielder->html('Text'),
)

$fielder->list($items = [])
// ..
...$fielder->list([
    $fielder->string('Title'),
    $fielder->html('Text'),
])

$fielder->tab($name, $titleOrField = null, $fields = null)
// ..
$fielder->tab('Primary tab', $fielder->header('Header'), $fielder->literal('Literal', '<b>Br</b>eaking <b>Ba</b>d'))

$fielder->tabSet($name, $titleOrTab = null, $tabs = null)
// ..
$fielder->tabSet('MyTabSetName',
    $fielder->tab('Primary tab', $fielder->header('Header'), $fielder->literal('Literal', '<b>Br</b>eaking <b>Ba</b>d')),
    $fielder->tab('Secondary tab', $fielder->header('Header'), $fielder->literal('Literal', '<b>Banshee</b>')),
)

$fielder->toggleComposite($name, $title, $children)
// ..
$fielder->toggleComposite('MyToggle', 'Toggle', [
    $fielder->string('Title'),
    $fielder->text('Text')
])

$fielder->upload($name, $title = null, SS_List $items = null)

$fielder->file($name, $title = null, $value = null)

$fielder->checkboxSet($name, $title = null, $source = [], $value = null)
// ..
$fielder->checkboxSet('List', 'List', [1 => 'Set 1', 2 => 'Set 2']),
// $source = FooBar::get()->map()

$fielder->dropdownTree($name, $title = null, $sourceObject = null, $keyField = 'ID', $labelField = 'TreeTitle', $showSearch = true)
// ..
$fielder->dropdownTree('Page')

$fielder->treeMultiSelect($name, $title = null, $sourceObject = Group::class, $keyField = "ID", $labelField = "Title")

$fielder->grid($name, $title = null, SS_List $dataList = null, GridFieldConfig $config = null)
// ..
$fielder->grid('Services', 'Services')->build()
// ..
$fielder->grid('Services', 'Services', $this->Services())->build()
// ..
$fielder->grid('Cards', 'Cards')
    ->config('default')
    ->components([
        'add',
        'edit',
    ])
    ->remove([
        'add',
        'edit',
        'copy',
        'delete',
    ])->build()

$fielder->listbox($name, $title = null, $source = [], $value = null, $size = null)

$fielder->header($name, $title = null, $headingLevel = 2)

$fielder->hidden($name, $title = null, $value = null)

$fielder->label($name, $title = null)

$fielder->literal($name, $content)

$fielder->nullable(FormField $valueField, $isNullLabel = null)
// ..
$fielder->nullable($fielder->string('Text'))

$fielder->decimal($name, $title = null, $wholeSize = 9, $decimalSize = 2, $defaultValue = 0)

$fielder->double($name, $title = null, $defaultVal = 0)

$fielder->float($name, $title = null, $defaultVal = 0)

$fielder->year($name, $title = null, $options = [])

$fielder->percentage($name, $title = null, $precision = 4)

$fielder->int($name, $title = null, $defaultVal = 0)

$fielder->bigInt($name, $title = null, $defaultVal = 0)

$fielder->locale($name, $title = null, $size = 16)

$fielder->enum($name)

$fielder->siteTreeURLSegment($name, $title = null, $value = '', $maxLength = null, $form = null)

$fielder->htmlReadonly($name, $title = null, $value = null)

$fielder->shortcode($name, $title = null)

$fielder->objectLink($relationName, $fieldName = null, $title = null, GridFieldConfig $customConfig = null, $useAutocompleter = true)

$fielder->object($relationName, $title = null, $linkConfig = [], $useAutocompleter = false)

$fielder->multiSelect($name, $title = null, $sort = false, $source = null, $titleField = 'Title')
// ..
$fielder->multiSelect('Services'),
$fielder->multiSelect('Services', 'Services', 'SortExtra'),

...$fielder->media($name, $title = null)

...$fielder->mediaSortable($name, $title = null)

$fielder->color($name, $title = null, $source = [], $value = null)
// ..
$fielder->color('Color', 'Color', ['yellow' => '#fee12f', 'pink' => '#eb83ad', 'green' => '#70cd77'])

$fielder->colorPicker($name, $title = null, $value = '', $form = null)

$fielder->colorGroup($name, $title = null, $source = [], $value = null)
// ..
$fielder->colorGroup('Color', 'Color', ['Primary' => ['yellow' => '#fee12f', 'pink' => '#eb83ad'], 'Secondary' => ['green' => '#70cd77']])

$fielder->json($name, $title = null, $options = [], $value = '{}', $form = null, $schema = '{}')

$fielder->json('Parameters')

$fielder->video($name, $title = null, $value = '', $static = false)

$fielder->place($name, $title = null, $value = '')

$fielder->map($name, $title = null, $value = '')

$fielder->link($name, $title = null, $value = null)

$fielder->links($name, $title = null, SS_List $dataList = null)

private static $has_one = [
    'Page' => \Page::class,
];

$fielder->linkSS($name, $title = null, $value = null)

$fielder->linkRel($name, $title = null, $linkConfig = [])
// ..
$fielder->linkRel('ALink', 'Link')

$fielder->code($name, $title = null, $value = null, $mode = 'ace/mode/html', $theme = 'ace/theme/github')

$fielder->tag($name, $title = null, $source = [], $value = null, $titleField = 'Title')

$fielder->points($name, $title = null, $source = [], $gridconfig = null)

use LittleGiant\SilverStripeImagePoints\DataObjects\Point;
use SilverStripe\Assets\Image;

private static $has_one = [
    'Image' => Image::class,
];

private static $has_many = [
    'ImagePoints' => Point::class . '.PointOf',
];

private static $owns = [
    'Image',
];

$fielder->points('ImagePoints')

$fielder->wrapper($children)
bash
php taz make:rule PhoneRule
php
$fielder->autocomplete($name, $title = null, $value = '', $sourceClass = null, $sourceFields = null)
// ..
$fielder->autocomplete('Page', 'Page', '', Page::class, 'Title')
php
$fielder->stringTag($name, $title = null, $source = [], $value = null)
// ..
$fielder->stringTag('Varchar', 'Varchar', MyDataObject::get())
php
$fielder->imageCoords($name, $title, $onlyCanvas = false, $cssGrid = false, $image = null, $XFieldName = null, $YFieldName = null, $xySumFieldName = null, $width = null, $height = null)
// ..
$fielder->imageCoords('Image', 'Focus Point', true)
$fielder->imageCoords('Image', 'Focus Point')
php
$fielder->encrypt($name)
php
$fielder->country($name, $title = null, $source = [], $value = '', $form = null)
php
$fielder->icon($set, $name, $title = null, $value = '')
php
$fielder->phone($name, $title = null, $options = [])
php
$fielder->mediaSelect($name, $relationList, $title = null)
// ..
$fielder->mediaSelect('Image', 'Images')