Allows overriding the output of custom fields.
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_output
-
field_output:jr_status
Returning boolean false
from the filter hides the custom field. The universal variation runs before the field-specific one.
Parameters
$output
(array) Field output before PHP output format setting code is processed
$field
(array) current field data
$entry
(array) listing or review data depending on the type of custom field
$instance
(CustomFieldsHelper) instance of current class
$name
(string) current field name
You need to have a working knowledge of Hooks before you get started.
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
// For JReviews 3.x and earlier use dd instead of fwd_dd
// fwd_dd($output, $field, $entry, $instance, $name);
return $output;
});
Development & Support
Customizations are not included with support. We provide this information to make it easier for developers to extend the functionality. From time to time we may have some availability for custom work. Get in touch to see if there's an opportunity to work together.
Examples
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
-
/views/helpers/custom_fields.php