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()
$fieldFactory : \Dewdrop\Fields\RowCollectionEditor\FieldFactory
A factory for creating a Field object enabling editing or viewing or data in this collection.
$request : \Dewdrop\Request
A Request object used to give this collection access to POST data.
__construct(string $id, \Dewdrop\Request $request = null)
Supply an ID for this collection.
setFieldFactory(\Dewdrop\Fields\RowCollectionEditor\FieldFactory $fieldFactory) : $this
Supply an alternate factory for generating field objects for this collection.
getFieldFactory() : \Dewdrop\Fields\RowCollectionEditor\FieldFactory
Get a field factory that can be used to build a Field object representing this collection.
setTitlesFromTable(\Dewdrop\Db\Table $table) : $this
Set the titles for this collection using the titles from a Table object.
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.
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.
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.
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.
getBlankEditor() : \Dewdrop\Fields\RowEditor
Get a blank RowEditor instance with no data associated with it.
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.