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)); + } + ], + ]);