can_write_field
Filter user permission to see a custom field in submit forms.
You need to have a working knowledge of Hooks before you get started.
Parameters
Name | Type | Description |
---|---|---|
$permission |
parameter |
(boolean) |
$params |
parameter |
(array) associative array with contextual data |
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('can_write_field', function($permission, $params)
{
// Uncomment line below to view available data passed into hook
// fwd_dd($permission, $params);
return $permission;
});
Examples
Prevent Changes to Custom Fields Content on Listing Updates
In this example users can fill out the content for fields `jr_fieldone`, `jr_fieldtwo`, `jr_fieldthree` while creating a new listing, but they are prevented from changing them afterwards. Only administrators will have access to the fields while editing listings.
Clickfwd\Hook\Filter::add('can_write_field', function($permission, $params)
{
$auth = S2Object::make('auth');
$fieldNames = ['jr_fieldone','jr_fieldtwo','jr_fieldthree'];
if ($auth->admin || $params['referrer'] !== 'listing.update')
{
return $permission;
}
if (in_array($params['field']['name'], $fieldNames))
{
return false;
}
return $permission;
});
Source Files
/services/authorization/listing_permissions.php