From a07e4466e00d0e1987d6cab0bef04658657e2ffe Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 20 Jan 2018 21:16:52 -0500 Subject: [PATCH] docs: add documentation for extra formatter options --- docs/_partials/fields/formatter-callable.rst | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/_partials/fields/formatter-callable.rst b/docs/_partials/fields/formatter-callable.rst index 22dd1985..b8e941f6 100644 --- a/docs/_partials/fields/formatter-callable.rst +++ b/docs/_partials/fields/formatter-callable.rst @@ -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: @@ -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)); + } + ], + ]);