jreviews:listing_form.custom_fields:{:name}
Filters whether a specific custom field should be shown in the listing form. The `{:name}` placeholder is the custom field name, for example `jr_featured`. Fires for each field in the collection.
You need to have a working knowledge of Hooks before you get started.
Fires for each field after the collection-level hook, allowing granular per-field control
Parameters
| Name | Type | Description |
|---|---|---|
$show |
bool |
Whether to show the field (true) or hide it (false) |
$field |
\JReviews\App\Models\Field |
The custom field model |
$listing |
\JReviews\App\Models\Listing |
The listing being created or edited |
Variations
This dynamic hook fires for each of the following variations. The {:name} placeholder in the hook name is replaced with one of these values:
For example, to target the - `jreviews:listing_form.custom_fields:jr_city` - For field with name 'jr_city' - `jreviews:listing_form.custom_fields:jr_featured` - For field with name 'jr_featured' - Pattern follows field name exactly variation, you would use:
fwd_add_filter('jreviews:listing_form.custom_fields:- `jreviews:listing_form.custom_fields:jr_city` - For field with name 'jr_city' - `jreviews:listing_form.custom_fields:jr_featured` - For field with name 'jr_featured' - Pattern follows field name exactly', function($show, $field, $listing)
{
// Your code here
return $show;
}, 20, 3);
Boilerplate Code
Use the boilerplate code to start using the filter, and add your own logic to modify the first argument and return it.
fwd_add_filter('jreviews:listing_form.custom_fields:{:name}', function($show, $field, $listing)
{
// Your code here
return $show;
}, 20, 3);
The , 20, N after your callback are the hook priority and the number of arguments your callback accepts. By default, a hook passes your callback only its first argument; for a filter, that is the value being filtered, so a simple function($value) { ... } needs nothing extra. If your callback declares more parameters, such as function($value, $listing) { ... }, you must add N (the parameter count, 2 here). Because N is the fourth argument to fwd_add_filter() or fwd_add_action(), you must also pass the priority (20 is the default). Leaving these off when your callback expects extra parameters causes a Too few arguments to function ... fatal error.
Examples
Show an internal field only to managers
Restrict a field to site managers/editors.
fwd_add_filter('jreviews:listing_form.custom_fields:jr_internal_notes', function($show, $field, $listing) {
$user = fwd_auth()->user();
return $show && $user && $user->isManager();
}, 20, 3);
Source Files
app/Http/Site/Yoyo/Listing/AbstractForm.php