$fields
$fields : array
The fields currently contained in this collection.
A group of fields in a \Dewdrop\Fields\GroupedFields collection. Each group has a title and a number of fields. It is a superset of the \Dewdrop\Fields API, so you can still call getVisibleFields(), getEditableFields(), etc. on a group. Adding and removing fields from a group will also change the underlying \Dewdrop\Fields\GroupedFields object.
1) Leverage metadata from the database (e.g. information about various constraints, data-types, etc.) to make working with database fields in various contexts simpler and less error-prone.
2) To allow the definition of non-DB-related fields as well, so that the Fields API can be used to inject customizable pieces of code into logic and rendering loops in a clean way.
Adding fields is possible in a few different ways. You can add a DB field directly from a \Dewdrop\Db\Table model:
$fields->add($model->field('my_field'));
You can add a custom field by passing an ID string to the add() method and then customizing the field:
$fields->add('my_custom_field_id') ->setLabel('Just a Custom Field') ->setVisible(true) ->assignHelperCallback( 'TableCell.Content', function ($helper, array $rowData) { return 'Hello, world'; } );
Or, you can instantiate and add the field object directly:
$field = new \Dewdrop\Fields\Field(); $field ->setId('my_custom_field_id') ->setLabel('Just a Custom Field') ->setVisible(true) ->assignHelperCallback( 'TableCell.Content', function ($helper, array $rowData) { return 'Hello, world'; } ); $fields->add($field);
Once added, you can get your fields back in a number of different ways:
1) The DOM-like get(), has(), and remove() methods all take a field ID.
2) The getAll(), getVisibleFields(), getSortableFields(), getFilterableFields() and getEditableFields() objects all will return new \Dewdrop\Fields objects that contain only the fields allowed by the method you called. When calling any of this methods, you can pass any number of \Dewdrop\Fields\Filter objects as well to further sort or limit the fields you get back.
3) You can iterate over the Fields object just like an array.
Many other objects in Dewdrop can receive a Fields collection and use it to make decisions. For example, notable view helpers such as Table can use a collection of fields to render their headers and cells.
$groupedFields : \Dewdrop\Fields\GroupedFields
The \Dewdrop\Fields\GroupedFields object containing this group.
__construct(\Dewdrop\Fields\GroupedFields $groupedFields, \Dewdrop\Fields\UserInterface $user = null)
Supply the GroupedFields object that contains this group.
\Dewdrop\Fields\GroupedFields | $groupedFields | |
\Dewdrop\Fields\UserInterface | $user |
getIterator() : \Dewdrop\Fields\FieldsIterator
Iterate over this Fields set using a FieldsIterator. You typically don't call this directly, you just do a foreach over the Fields object.
insertAfter(\Dewdrop\Fields\FieldInterface|string $field, \Dewdrop\Fields\FieldInterface|string $after, string $modelName = null) : \Dewdrop\Fields\FieldInterface
Add the supplied field to this collection after another specified field already in the collection. Can be a FieldInterface object or a string, in which case a new custom field will be added with the supplied string as its ID.
The newly added FieldInterface object is returned from this method so that it can be further customized immediately, using method chaining. Once you've completed calling methods on the FieldInterface object itself, you can call any \Dewdrop\Fields methods to return execution to that context.
\Dewdrop\Fields\FieldInterface|string | $field | |
\Dewdrop\Fields\FieldInterface|string | $after | |
string | $modelName |
setUser(\Dewdrop\Fields\UserInterface $user) : \Dewdrop\Fields
Set the UserInterface object that can be used by the authorization-related features in \Dewdrop\Fields.
\Dewdrop\Fields\UserInterface | $user |
getUser() : \Dewdrop\Fields\UserInterface
Get the user object associated with these fields.
has(string $id, integer $position = null) : boolean
Check to see if a field with the given ID exists in this collection. If the identified field does exist, then the $position output parameter is populated with the position of the field in the collection, starting at 0.
string | $id | |
integer | $position |
get(string $id) : \Dewdrop\Fields\FieldInterface
Get the field matching the supplied ID from this collection.
string | $id |
getByQueryStringId(string $id) : \Dewdrop\Fields\FieldInterface
Get the field matching the supplied query string ID from this collection.
string | $id |
add(mixed $field, string $modelName = null) : \Dewdrop\Fields\GroupedFields\FieldInterface
Add a field to this group and the underlying GroupedFields object.
The newly added FieldInterface object is returned from this method so that it can be further customized immediately, using method chaining. Once you've completed calling methods on the FieldInterface object itself, you can call any \Dewdrop\Fields methods to return execution to that context.
mixed | $field | |
string | $modelName |
prepend(mixed $field, string|null $modelName = null) : \Dewdrop\Fields\FieldInterface
Prepend the supplied field (or custom field ID) to the field set.
mixed | $field | |
string|null | $modelName |
append(mixed $field, string|null $modelName = null) : \Dewdrop\Fields\FieldInterface
An alias to add(). Just here because it's odd to have prepend() and not append().
mixed | $field | |
string|null | $modelName |
remove(string $id) : \Dewdrop\Fields\GroupedFields\Group
Remove a field from this group and the GroupedFields container.
string | $id |
getAll(mixed $filters = null) : \Dewdrop\Fields
Get all the fields currently in this collection.
mixed | $filters |
getVisibleFields(mixed $filters = null) : \Dewdrop\Fields
Get any fields that are visible and pass the supplied filters. Note that you can either pass a single \Dewdrop\Fields\Filter or an array of them.
mixed | $filters |
getSortableFields(mixed $filters = null) : \Dewdrop\Fields
Get any fields that are sortable and pass the supplied filters. Note that you can either pass a single \Dewdrop\Fields\Filter or an array of them.
mixed | $filters |
getEditableFields(mixed $filters = null) : \Dewdrop\Fields
Get any fields that are editable and pass the supplied filters. Note that you can either pass a single \Dewdrop\Fields\Filter or an array of them.
mixed | $filters |
getFilterableFields(mixed $filters = null) : \Dewdrop\Fields
Get any fields that are filterable and pass the supplied filters. Note that you can either pass a single \Dewdrop\Fields\Filter or an array of them.
mixed | $filters |
setTitle(string $title) : \Dewdrop\Fields\GroupedFields\Group
Set the title for this group. This will show up when the group is display (e.g. in a UI tab).
string | $title |
handleModelsForDbField(\Dewdrop\Db\Field $field, string $modelName)
Handle the model (\Dewdrop\Db\Table) objects for the supplied newly added DB field. We allow custom model names for situations where you need to add fields from two different instances of the same model (e.g. you have an two Addresses model instances on your fields set because you have both a billing and a shipping address).
\Dewdrop\Db\Field | $field | |
string | $modelName |
getFieldsPassingMethodCheck(string $fieldMethodName, mixed $filters) : \Dewdrop\Fields
Get any fields that return true when the supplied method is called and pass the supplied filters. Note that you can either pass a single \Dewdrop\Fields\Filter or an array of them.
string | $fieldMethodName | |
mixed | $filters |
applyFilters(\Dewdrop\Fields $fields, mixed $filters) : \Dewdrop\Fields
Apply the supplied filters to the Fields. You can pass no filters, a single filter, or an array of filters.
\Dewdrop\Fields | $fields | |
mixed | $filters |
prepareFieldForAdding(mixed $field, string|null $modelName = null) : \Dewdrop\Fields\FieldInterface
Prepare to add a field for the supplied arguments. If $field is a string we'll create a new CustomField. Otherwise, we'll just directly add the field object itself.
mixed | $field | |
string|null | $modelName |