Skip to content

Commit

Permalink
docs: add documentation for extra formatter options
Browse files Browse the repository at this point in the history
  • Loading branch information
josegonzalez authored Jan 21, 2018
1 parent edd48d6 commit a07e446
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion docs/_partials/fields/formatter-callable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ Formatting with a Callable

The most immediate way of formatting a field is by passing a callable function
or object to the ``formatter`` option. Callable functions or objects will
receive 3 arguments:
receive 5 arguments:

* ``$name`` The name of the field to be displayed
* ``$value`` The value of the field that should be outputted
* ``$entity`` The entity object from which the field was extracted
* ``$options`` An array of options passed to the CrudView helper when the field is being processed
* ``$View`` The view object in use during formatting

For example, imagine that when displaying the ``published_time`` property, we
wanted to also display who approved the article:
Expand Down Expand Up @@ -42,3 +44,17 @@ only configure the settings for one or two.
}
],
]);
In some cases, it may be useful to access a helper within the callable. For instance, you might want to create a link:

.. code-block:: php
$action = $this->Crud->action();
$action->config('scaffold.fields', [
'title',
'external_id' => [
'formatter' => function ($name, $value, $entity, $options, $View) {
return $View->Html->link($name, sprintf('https://example.com/view/%d', $value));
}
],
]);

0 comments on commit a07e446

Please sign in to comment.