diff --git a/docs/customizing-templates.rst b/docs/customizing-templates.rst index 22cbac54..21b7db5b 100644 --- a/docs/customizing-templates.rst +++ b/docs/customizing-templates.rst @@ -66,6 +66,31 @@ applying formatters to any of your fields. Whenever you use the } } +You may also specify formatters using the ``scaffold.field_settings`` +configuration key. This is useful if you want to display all fields but wish +to only configure the settings for one or two. + +.. code-block:: php + + Crud->action(); + $action->config('scaffold.field_settings', [ + 'published_time' => [ + 'formatter' => function ($name, Time $value) { + return $value->nice(); + } + ], + ]); + return $this->Crud->execute(); + } + } + Formatting with a Callable ~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/Listener/ViewListener.php b/src/Listener/ViewListener.php index 001daa62..4e6f7ab5 100644 --- a/src/Listener/ViewListener.php +++ b/src/Listener/ViewListener.php @@ -307,11 +307,12 @@ protected function _scaffoldFields(array $associations = []) $scaffoldFields[$field] += ['formatter' => null]; } - $fieldFormatters = $action->config('scaffold.field_formatters'); - if (empty($fieldFormatters)) { - $fieldFormatters = []; + $fieldSettings = $action->config('scaffold.field_settings'); + if (empty($fieldSettings)) { + $fieldSettings = []; } - $scaffoldFields = Hash::merge($scaffoldFields, $fieldFormatters); + $fieldSettings = array_intersect_key($fieldSettings, $scaffoldFields); + $scaffoldFields = Hash::merge($scaffoldFields, $fieldSettings); return $scaffoldFields; }