can_write_field

Filter Hook Field Permissions

Filter user permission to see a custom field in submit forms.

Parameters

$permission

(boolean)

$params

(array) associative array with contextual data

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('can_write_field', function($permission, $params) 
{
  // Uncomment line below to view available data passed into hook
  // For JReviews 3.x and earlier use dd instead of fwd_dd
  // fwd_dd($permission, $params);
  
  return $permission;
});
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

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

  • /services/authorization/listing_permissions.php