This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi,
im having problems with the following function:
public function filterFields($fields, $context = null)
{
if (!$backendUser = BackendAuth::getUser())
throw new \Exception('No admin logged in');
$authorChangeAllowed = $backendUser->hasPermission('vendor.plugin.manage_all_news');
// dd($fields->author);
if ($authorChangeAllowed) {
$fields->author->hidden = false;
} else {
$fields->author->hidden = true;
}
}
As described in the docs, the function allows for additional form field filtering. What I'm doing is quite obvious, restricting a single field (author - type: relation) from being visible by setting the hidden
property of the field. For some reason I get the following PHP warning/error Creating default object from empty value
. What's wrong with the code?
Regards Jakob
Last updated
Strangely in another model class I'm doing almost the same thing and have no problems:
public function filterFields($fields, $context = null)
{
if ($fields->status->value === 'invited') {
$fields->appointment_description->hidden = false;
} else {
$fields->appointment_description->hidden = true;
}
}
The filterFields
method is used recursively on the fields of a (in this case also present) repeater
field. That's why some class properties named after fields are not present.
Everything is explained here: https://github.com/octobercms/october/issues/1792
1-3 of 3