hasField('access')) { return; } $model->applyAccessFiltering(null); } /** * The event runs after DataModel has retrieved a single item from the database. It is used to apply automatic * filters. * * @param DataModel &$model The model which was called * @param Array &$keys The keys used to locate the record which was loaded * * @return void */ public function onAfterLoad(&$model, &$keys) { // Make sure we have a DataModel if (!($model instanceof DataModel)) { return; } // Make sure the field actually exists if (!$model->hasField('access')) { return; } // Get the user $user = $model->getContainer()->platform->getUser(); $recordAccessLevel = $model->getFieldValue('access', null); // Filter by authorised access levels if (!in_array($recordAccessLevel, $user->getAuthorisedViewLevels())) { $model->reset(true); } } }