\Dewdrop\FieldsRowCollectionEditor

The RowCollectionEditor provides an API for editing a variable-sized collection of items. Each item in the collection will get its own Fields and RowEditor objects, allowing you to leverage the validation/filtering and data handling capabilities in RowEditor while not having to manually track dynamically created rows.

To do this, you'll supply RowCollectionEditor with three callbacks:

1) setFetchDataCallback() 2) setFieldsCallback() 3) setRowEditorCallback()

Summary

Methods
Properties
Constants
__construct()
setFieldFactory()
getFieldFactory()
setId()
getId()
setTitlesFromTable()
setTitle()
getTitle()
setPluralTitle()
getPluralTitle()
setSingularTitle()
getSingularTitle()
setRowEditorCallback()
setFieldsCallback()
setFetchDataCallback()
isValid()
save()
getData()
getFields()
resetEditors()
getEditors()
getBlankEditor()
No public properties found
DATA_MODE_CONTROL_NAMES
DATA_MODE_COLUMN_NAMES
No protected methods found
No protected properties found
N/A
instantiateEditor()
getDataFromRequest()
createDeleteField()
$id
$title
$pluralTitle
$singularTitle
$fieldFactory
$editors
$request
$fieldsCallback
$fetchDataCallback
$rowEditorCallback
N/A

Constants

DATA_MODE_CONTROL_NAMES

DATA_MODE_CONTROL_NAMES

DATA_MODE_COLUMN_NAMES

DATA_MODE_COLUMN_NAMES

Properties

$id

$id : string

The ID for the collection. Used in input names, etc.

Type

string

$title

$title : string

A default title.

Type

string

$pluralTitle

$pluralTitle : string

A default title.

Type

string

$singularTitle

$singularTitle : string

A default title.

Type

string

$editors

$editors : array

The RowEditor objects created by this collection.

Type

array

$request

$request : \Dewdrop\Request

A Request object used to give this collection access to POST data.

Type

\Dewdrop\Request

$fieldsCallback

$fieldsCallback : callable

A callback used to build a Fields object for each RowEditor created by this collection.

Type

callable

$fetchDataCallback

$fetchDataCallback : callable

A callback used to fetch an initial data set for this collection.

Type

callable

$rowEditorCallback

$rowEditorCallback : callable

A callback used to configure RowEditors produced by this collection.

Type

callable

Methods

__construct()

__construct(string  $id, \Dewdrop\Request  $request = null) 

Supply an ID for this collection.

Parameters

string $id
\Dewdrop\Request $request

setFieldFactory()

setFieldFactory(\Dewdrop\Fields\RowCollectionEditor\FieldFactory  $fieldFactory) : $this

Supply an alternate factory for generating field objects for this collection.

Parameters

\Dewdrop\Fields\RowCollectionEditor\FieldFactory $fieldFactory

Returns

$this

setId()

setId(  $id) : $this

Set the ID for this collection.

Parameters

$id

Returns

$this

getId()

getId() : string

Get the ID for this collection.

Returns

string

setTitlesFromTable()

setTitlesFromTable(\Dewdrop\Db\Table  $table) : $this

Set the titles for this collection using the titles from a Table object.

Parameters

\Dewdrop\Db\Table $table

Returns

$this

setTitle()

setTitle(  $title) : $this

Set a title for this collection.

Parameters

$title

Returns

$this

getTitle()

getTitle() : string

Get a title for this collection.

Returns

string

setPluralTitle()

setPluralTitle(string  $pluralTitle) : $this

Set a plural title for this collection.

Parameters

string $pluralTitle

Returns

$this

getPluralTitle()

getPluralTitle() : string

Get a plural title for this collection.

Returns

string

setSingularTitle()

setSingularTitle(string  $singularTitle) : $this

Set a singular title for this collection.

Parameters

string $singularTitle

Returns

$this

getSingularTitle()

getSingularTitle() : string

Get a singular title for this collection.

Returns

string

setRowEditorCallback()

setRowEditorCallback(callable  $rowEditorCallback) : $this

Set the callback you'll use to configure each RowEditor created by this collection. You'll use this callback to set a delete field, set defaults (e.g. to link the RowEditor back to parent RowEditor this collection is attached to), link rows together by their foreign keys, etc.

Parameters

callable $rowEditorCallback

Returns

$this

setFieldsCallback()

setFieldsCallback(callable  $fieldsCallback) : $this

Set the callback you'll use to build a Fields object for each RowEditor created by this collection. Your fields callback will receive the empty Fields objects as its first and only argument, so you don't have to instantiate or return it yourself. Not that you'll want to use new Table objects to get your Field objects each time this callback is called to ensure each RowEditor operates independently from the others.

Parameters

callable $fieldsCallback

Returns

$this

setFetchDataCallback()

setFetchDataCallback(callable  $fetchDataCallback) : $this

Set the callback you'll use to fetch the initial data set for the collection.

Parameters

callable $fetchDataCallback

Returns

$this

isValid()

isValid() : boolean

Check to see if all editors associated with this collection are valid.

Returns

boolean

save()

save() : boolean

Save all editors. We assume that you've already used isValid() to populate all editors with the request data and ensure they're valid prior to calling save(). We also check to see if any editors are queued for deletion at this point and will call their delete() method rather than save() if that's the case.

Returns

boolean

getData()

getData(string  $mode = self::DATA_MODE_COLUMN_NAMES) : array|mixed

Fetch data for this collection. If your request is a POST, then we'll get the data from the request. If it's not a POST, we ask the fetchDataCallback for the initial data set.

Parameters

string $mode

Returns

array|mixed

getFields()

getFields() : \Dewdrop\Fields

Get a Fields object for this collection not associated with any RowEditor. Useful for rendering a table displaying all the collection's data, for example.

Returns

\Dewdrop\Fields

resetEditors()

resetEditors() : $this

Reset editors. Useful if your data changes and you want to build all the editors again to reflect that.

Returns

$this

getEditors()

getEditors() : array

Get all data-based (rather than blank) editors from this collection.

Returns

array

getBlankEditor()

getBlankEditor() : \Dewdrop\Fields\RowEditor

Get a blank RowEditor instance with no data associated with it.

Returns

\Dewdrop\Fields\RowEditor

instantiateEditor()

instantiateEditor(array  $data, mixed  $index = null) : \Dewdrop\Fields\RowEditor

Instantiate a new RowEditor instance using the supplied data. The fields for the RowEditor will be build by your fieldsCallback. All fields will then have their HTML ID and control names manipulated to allow for them to be submitted back as arrays and to avoid naming collisions.

Parameters

array $data
mixed $index

Returns

\Dewdrop\Fields\RowEditor

getDataFromRequest()

getDataFromRequest(array  $request, string  $mode) : array

Get the data for this collection from the supplied request data.

Parameters

array $request
string $mode

Returns

array