Skip to content

Commit

Permalink
Add documentation on customizing field settings with autoFields turne…
Browse files Browse the repository at this point in the history
…d on
  • Loading branch information
josegonzalez committed Dec 28, 2015
1 parent 2eff510 commit 41f4a34
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
25 changes: 25 additions & 0 deletions docs/customizing-templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php
namespace App\Controller;
class ArticlesController extends AppController
{
public function index()
{
$action = $this->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
~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
9 changes: 5 additions & 4 deletions src/Listener/ViewListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 41f4a34

Please sign in to comment.