field_output{:name}
Allows overriding the output of custom fields.
You need to have a working knowledge of Hooks before you get started.
This filter is similar to the PHP output format setting, but more convinient if you are doing a lot of field output customizations. There are two variations for this filter, universal for all fields and field-specific:
field_outputfield_output:jr_status
Returning boolean false from the filter hides the custom field. The universal variation runs before the field-specific one.
Parameters
| Name | Type | Description |
|---|---|---|
$output |
parameter |
(array) Field output before PHP output format setting code is processed |
$field |
parameter |
(array) current field data |
$entry |
parameter |
(array) listing or review data depending on the type of custom field |
$instance |
parameter |
(CustomFieldsHelper) instance of current class |
$name |
parameter |
(string) current field name |
Boilerplate Code
Use the boilerplate code to start using the filter, and add your own logic to modify the first argument and return it.
Clickfwd\Hook\Filter::add('field_output-name', function($output, $field, $entry, $instance, $name)
{
// Uncomment line below to view available data passed into hook
// fwd_dd($output, $field, $entry, $instance, $name);
return $output;
});
Examples
- Show field output only to listing owner and admins
- Re-order output of multi-select fields alphabetically
Show field output only to listing owner and admins
Clickfwd\Hook\Filter::add('field_output:jr_notes', function($output, $field, $listing, $instance)
{
if ($instance->auth->admin || $instance->auth->matchesUserId($listing['User']['user_id'])) {
return $output;
}
return false;
});
Re-order output of multi-select fields alphabetically
When using the auto-complete UI for multiple select lists, the options are stored in the order in which they are selected. And a user can also re-order them by dragging and dropping the tags in the desired order. The following code will override the order of a specific field, `jr_cuisine`, and re-order the display options alphabetically.
Clickfwd\Hook\Filter::add('field_output:jr_cuisine', function($output, $field, $entry, $instance, $name)
{
return fwd_collect($output)->map(function($row) {
return [
'value' => strip_tags($row),
'html' => $row
];
})->sortBy('value')->pluck('html')->toArray();
});
Source Files
/views/helpers/custom_fields.php