\Dewdrop\Fields\Helper\TableCellContent

The header helper allows you to render the content of the header for a given field in a table (typically the <th> tag). When defining a custom callback for this helper, using the following callback parameters:

$tableCell->getContentRenderer()->assign(
    'my_model:my_field',
    function ($helper, array $rowData, $rowIndex, $columnIndex) {
        // Param $helper is a reference to this instance of the Header helper
        // Param $rowData if an associative array representing all the data available to render this table row.
        // Param $rowIndex is a zero-based index of the current row being rendered
        // Param $columnIndex is a zero-based index of the current column being rendered

        return '' . $helper->getView()->escapeHtml($row['my_field']) . ';
    }
);

Summary

Methods
Properties
Constants
matchesName()
assign()
getFieldAssignment()
hasValidName()
detectCallableForField()
__construct()
setViewMode()
isTableView()
isDetailView()
getView()
getEscaper()
setNullContentPlaceholder()
setDateFormat()
setTimeFormat()
render()
assignCallbackByColumnPosition()
No public properties found
VIEW_MODE_TABLE
VIEW_MODE_DETAIL
wrapCallable()
renderDbText()
renderDbReference()
renderDbBoolean()
renderDbDate()
renderDbTime()
renderDbTimestamp()
$name
$viewMode
N/A
No private methods found
$assignments
$view
$callbacksByColumnPosition
$nullContentPlaceholder
$dateFormat
$timeFormat
N/A

Constants

VIEW_MODE_TABLE

VIEW_MODE_TABLE

VIEW_MODE_DETAIL

VIEW_MODE_DETAIL

Properties

$name

$name : string

The name for this helper, used when you want to define a global custom callback for a given field

Type

string

$viewMode

$viewMode : string

The current view mode of this renderer. Either VIEW_MODE_TABLE or VIEW_MODE_DETAIL.

Type

string

$assignments

$assignments : array

Any per-instance callback assignments for this helper. This array will have field IDs as the keys and callables as the values.

Type

array

$view

$view : \Dewdrop\View\View

A view object used for rendering and escaping.

Type

\Dewdrop\View\View

$callbacksByColumnPosition

$callbacksByColumnPosition : array

It's possible to assign callbacks based upon column position/index. This can be useful if you want to automatically add some controls or other content to the first column, for example.

Type

array

$nullContentPlaceholder

$nullContentPlaceholder : string

This content will be returned if any field's callback generates no output.

Type

string

$dateFormat

$dateFormat : string

The default format for rendering dates. Uses PHP's date() syntax.

Type

string

$timeFormat

$timeFormat : string

The default format for rendering time. Uses PHP's date() syntax.

Type

string

Methods

matchesName()

matchesName(string  $name) : boolean

Check to see if the supplied input matches this helper's name (case-insensitive).

Parameters

string $name

Returns

boolean

assign()

assign(mixed  $assignments, callable  $callable = null) : \Dewdrop\Fields\Helper\HelperAbstract

Assign one more custom per-instance callbacks for this helper. If the $arguments param is an array, this method expects that the keys will be field IDs and the values will be callables, assigning custom callbacks for multiple fields in one call. If, however, $assignments is a string or a FieldInterface object, a single custom callback assignment will be made.

Parameters

mixed $assignments
callable $callable

Returns

\Dewdrop\Fields\Helper\HelperAbstract

getFieldAssignment()

getFieldAssignment(\Dewdrop\Fields\FieldInterface  $field) : callable

Get the callback that will be used for the given FieldInterface object.

Parameters

\Dewdrop\Fields\FieldInterface $field

Throws

\Dewdrop\Fields\Exception\HelperCallableNotAvailableForField

Returns

callable

hasValidName()

hasValidName() : boolean

Ensure the helper has a valid $name value. If not, throw an exception.

All helpers must have a name defined so that global custom callbacks can be added to fields.

Throws

\Dewdrop\Fields\Exception\HelperMustHaveName

Returns

boolean

detectCallableForField()

detectCallableForField(\Dewdrop\Fields\FieldInterface  $field) : mixed

If no custom callback is defined for a field, it will fall back to this method to find a suitable callback. In the case of the Content helper, we only provide a fall back for DB-based fields. Custom fields will have to define a callback in order to function properly.

If no callback candidate is found, just return false from this method, which will be detected by getFieldAssignment(), causing execution to halt.

Parameters

\Dewdrop\Fields\FieldInterface $field

Returns

mixed

__construct()

__construct(\Dewdrop\View\View  $view) 

Provide a Dewdrop view for rendering.

Parameters

\Dewdrop\View\View $view

setViewMode()

setViewMode(string  $viewMode) : $this

Switch the view mode of this renderer. Must by either VIEW_MODE_TABLE or VIEW_MODE_DETAIL. Allows callback authors to detect table view vs detail view and render accordingly.

Parameters

string $viewMode

Returns

$this

isTableView()

isTableView() : boolean

Check to see if this renderer is being used to render a table for multiple records rather than the details of a single record.

Returns

boolean

isDetailView()

isDetailView() : boolean

Check to see if this renderer is being used to render a single record's details rather than a collection of records.

Returns

boolean

getView()

getView() : \Dewdrop\View\View

Get the Dewdrop view object that can be used to render the cell's content and escape it to prevent XSS.

Returns

\Dewdrop\View\View

getEscaper()

getEscaper() : \Dewdrop\View\View

The TableCell helpers originally used an Escaper rather than a Dewdrop view object. This was limiting and also error-prone because Escaper fails to handle nulls well. The view API has all of Escaper's public methods, though, so returning it here, should not break any code.

Returns

\Dewdrop\View\View

setNullContentPlaceholder()

setNullContentPlaceholder(string  $nullContentPlaceholder) : \Dewdrop\Fields\Helper\TableCell\Content

Set the content that should be returned if a field's callback returns no output.

Parameters

string $nullContentPlaceholder

Returns

\Dewdrop\Fields\Helper\TableCell\Content

setDateFormat()

setDateFormat(string  $dateFormat) : \Dewdrop\Fields\Helper\TableCell\Content

Set an alternative format for date rendering. Uses PHP's date() syntax.

Parameters

string $dateFormat

Returns

\Dewdrop\Fields\Helper\TableCell\Content

setTimeFormat()

setTimeFormat(string  $timeFormat) : \Dewdrop\Fields\Helper\TableCell\Content

Set an alternative format for time rendering. Uses PHP's date() syntax.

Parameters

string $timeFormat

Returns

\Dewdrop\Fields\Helper\TableCell\Content

render()

render(\Dewdrop\Fields\FieldInterface  $field, array  $rowData, integer  $rowIndex, integer  $columnIndex) : string

Render the cell's content for the supplied field.

Parameters

\Dewdrop\Fields\FieldInterface $field
array $rowData
integer $rowIndex
integer $columnIndex

Returns

string

assignCallbackByColumnPosition()

assignCallbackByColumnPosition(integer  $columnIndex, callable  $callback) : \Dewdrop\Fields\Helper\TableCell\Content

Assign a callback based upon the column position currently being displayed. This can be useful, for example, if you'd like to display some controls/links in the first column of your table automatically.

You can wrap the callback that would have been used by calling the getFieldAssignment() method with the appropriate field object.

Parameters

integer $columnIndex
callable $callback

Returns

\Dewdrop\Fields\Helper\TableCell\Content

wrapCallable()

wrapCallable(callable  $callable, \Dewdrop\Fields\FieldInterface  $field = null) : callable

Wrap a field's callback to ensure that a reference to the helper is always supplied as the first argument to the callback.

Parameters

callable $callable
\Dewdrop\Fields\FieldInterface $field

Returns

callable

renderDbText()

renderDbText(\Dewdrop\Fields\FieldInterface  $field, array  $rowData) : string

A fall back method for basic DB fields. Just returns the escaped text for the field in your row's data.

Parameters

\Dewdrop\Fields\FieldInterface $field
array $rowData

Returns

string

renderDbReference()

renderDbReference(\Dewdrop\Fields\FieldInterface  $field, array  $rowData) : string

A fall back method for DB reference fields. For foreign keys, we trim the "_id" off the end and look for the resulting field in the resultset.

For example, if you foreign key is "state_id", we look for a resultset key of "state" and render that value for the field.

Parameters

\Dewdrop\Fields\FieldInterface $field
array $rowData

Returns

string

renderDbBoolean()

renderDbBoolean(\Dewdrop\Db\Field  $field, array  $rowData) : string

Render a simple yes/no for boolean fields. We do try to detect the difference between null and false values to support "tri-state" use of a boolean field.

Parameters

\Dewdrop\Db\Field $field
array $rowData

Returns

string

renderDbDate()

renderDbDate(\Dewdrop\Fields\FieldInterface  $field, array  $rowData) : string

A fall back method for date fields. Will convert the DB value to a Unix timestamp and then format it with PHP's date() function. (How retro!) You can customize the format with setDateFormat().

Parameters

\Dewdrop\Fields\FieldInterface $field
array $rowData

Returns

string

renderDbTime()

renderDbTime(\Dewdrop\Db\Field  $field, array  $rowData) : string

Parameters

\Dewdrop\Db\Field $field
array $rowData

Returns

string

renderDbTimestamp()

renderDbTimestamp(\Dewdrop\Fields\FieldInterface  $field, array  $rowData) : string

A fall back method for timestamp fields. Will convert the DB value to a Unix timestamp and then format it with PHP's date() function. (How retro!) You can customize the format with setDateFormat().

Parameters

\Dewdrop\Fields\FieldInterface $field
array $rowData

Returns

string