diff --git a/inc/form.class.php b/inc/form.class.php index 16b1340a9..75afbc8f7 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -2454,6 +2454,8 @@ public function validationRequired(): bool { * @return boolean true if the user can use the form */ public function canViewForRequest(): bool { + global $PLUGIN_HOOKS; + if ($this->isNewItem()) { return false; } @@ -2480,6 +2482,19 @@ public function canViewForRequest(): bool { return false; } + // Check plugins restrictions + foreach ($PLUGIN_HOOKS['formcreator_restrict_form'] as $plugin => $callable) { + // Skip if invalid hook + if (!is_callable($callable)) { + trigger_error("formcreator_restrict_form[$plugin]: not a callable", E_USER_WARNING); + continue; + } + + if (!call_user_func($callable, $this)) { + return false; + } + } + // All checks were succesful, display form return true; } @@ -2496,6 +2511,8 @@ public function showTagsList() { * get the SQL joins and conditions to select the forms available for the current user */ public static function getFormListQuery() { + global $PLUGIN_HOOKS; + $dbUtils = new DbUtils(); $formTable = getTableForItemType(PluginFormcreatorForm::class); $formLanguageTable = getTableForItemType(PluginFormcreatorForm_Language::class); @@ -2527,7 +2544,8 @@ public static function getFormListQuery() { 'access_rights' => ['!=', PluginFormcreatorForm::ACCESS_RESTRICTED], PluginFormcreatorFormAccessType::getRestrictedFormListCriteria(), ], - ] + ], + ...array_values($PLUGIN_HOOKS['formcreator_restrict_forms'] ?? []) ] + $entityRestrict, ], ];