-
Notifications
You must be signed in to change notification settings - Fork 42
Open
Description
Recently had a requirement to display a shorter name for a related field in the index table (from the default name field to one called short_name).
This is the most elegant solution I could come up with:
public function index()
{
$action = $this->Crud->action();
$action->config([
'scaffold.fields' => [
'facility_id' => [
'formatter' => function ($name, $value, $entity) {
return $this->getView()->Html->link(
$entity->facility->short_name,
['controller' => 'Facilities', 'action' => 'view', $entity->facility->id]
);
}
],Other things I tried included:
- Using an element formatter (though getting all the information I needed to create the link in a reusable way, such as the target controller name, wasn't pretty so I abandoned that idea.)
- Changing the display field on the association (we needed the full name in the search filters, so this involved changing the displayField in
beforePaginateand back again inrelatedModel, which wasn't ideal either.)
Is this a common enough use case where it should be configurable like like title and label?
public function index()
{
$action = $this->Crud->action();
$action->config([
'scaffold.fields' => [
'facility_id' => ['displayField' => 'short_name'],Metadata
Metadata
Assignees
Labels
No labels