2017 © Pedro Peláez
 

silverstripe-module zen-fields

Syntactic sugar for SilverStripe FieldLists

image

unclecheese/zen-fields

Syntactic sugar for SilverStripe FieldLists

  • Monday, May 19, 2014
  • by unclecheese
  • Repository
  • 5 Watchers
  • 29 Stars
  • 13,928 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 6 Open issues
  • 4 Versions
  • 2 % Grown

The README.md

Zen Fields for SilverStripe

Syntactic sugar for your SilverStripe FieldLists., (*1)

Basic Usage

<?php
$fields
  ->text("FirstName")
  ->numeric("Age");

Is syntactic sugar for:, (*2)

<?php
$fields->addFieldToTab("Root.Main", TextField::create("FirstName", "First Name"),"Content");
$fields->addFieldToTab("Root.Main", TextField::create("Age", "Age"),"Content");

In FieldLists with TabSets, the tab is assumed to be "Root.Main", unless otherwise specified. Labels are automatically generated from field names when not provided. Wildcard field methods are any subclass of FormField, with the "Field" suffix removed, and with a lowercase first letter. Examples: * text() -> TextField * currency() -> CurrencyField * treeDropdown() -> TreeDropdownField, (*3)

Specifying tabs

<?php
$fields
  ->tab("PersonalInfo")
    ->text("FirstName")
    ->numeric("Age")
  ->tab("Qualifications")
    ->grid("Qualifications","Qualifications", $this->Qualifications(), GridFieldConfig_RecordEditor::create());

Mutating fields after instantiation

For chainability, each method returns the FieldList, so in order to access the FormField object, you must use the configure() accessor, followed by end() to return to the FieldList object., (*4)

<?php
$fields
  ->dropdown("PickOne")
    ->configure()
      ->setSource(array('1' => 'One', '2' => 'Two'))
      ->setEmptyString("-- None --")
    ->end()
  ->text("Title");

Is syntactic sugar for:, (*5)

<?php
$fields->addFieldToTab("Root.Main", DropdownField::create("PickOne","Pick One")
  ->setSource(array('1' => 'One', '2' => 'Two'))
  ->setEmptyString("-- None --")
);
$fields->addFieldToTab("Root.Main", TextField::create("Title"));

Grouping fields

You can instantiate a FieldGroup with the group() method., (*6)

<?php
$fields
  ->text("Name")
  ->group()
    ->text("Address")
    ->text("City")
    ->text("PostalCode")
  ->end();

Is syntactic sugar for:, (*7)

<?php
$fields->addFieldToTab("Root.Main", TextField::create("Name"));
$fields->addFieldToTab("Root.Main", FieldGroup::create(
  TextField::create("Address"),
  TextField::create("City")
  TextField::create("PostalCode")
));

Extras

There are a few shortcut methods for adding common field configurations., (*8)

<?php
$fields
  ->imageUpload("MyImage")
  ->hasManyGrid("RelatedObjects","Related objects", $this->RelatedObjects())
    ->configure()->addDragAndDrop("Sort")->end();

The Versions

19/05 2014

dev-master

9999999-dev

Syntactic sugar for SilverStripe FieldLists

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe forms fields fieldlist

19/05 2014

1.0.2

1.0.2.0

Syntactic sugar for SilverStripe FieldLists

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe forms fields fieldlist

18/02 2014

1.0.1

1.0.1.0

Syntactic sugar for SilverStripe FieldLists

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe forms fields fieldlist

19/12 2013

1.0.0

1.0.0.0

Syntactic sugar for SilverStripe FieldLists

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe forms fields fieldlist