\Dewdrop\Fields\Helper\TableCellTdClassNames

The TdClassNames helper allows you to render a CSS class string that will be added to the <td> of your table cell. 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()
getView()
getEscaper()
render()
No public properties found
No constants found
wrapCallable()
$name
N/A
No private methods found
$assignments
$view
N/A

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

$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

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) : callable

By default, we just return an empty string if there was not custom callback found for a field.

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

callable

__construct()

__construct(\Dewdrop\View\View  $view) 

Provide a Dewdrop view for rendering.

Parameters

\Dewdrop\View\View $view

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

render()

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

Render a CSS class string for the field's table cell. Your callback can return either a string or an array of classes.

Parameters

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

Returns

string

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