Skip to content

Commit

Permalink
Add form visibility hook
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienClairembault authored and btry committed Mar 30, 2022
1 parent bc5c7ee commit 032c4c1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -2527,7 +2544,8 @@ public static function getFormListQuery() {
'access_rights' => ['!=', PluginFormcreatorForm::ACCESS_RESTRICTED],
PluginFormcreatorFormAccessType::getRestrictedFormListCriteria(),
],
]
],
...array_values($PLUGIN_HOOKS['formcreator_restrict_forms'] ?? [])
] + $entityRestrict,
],
];
Expand Down

0 comments on commit 032c4c1

Please sign in to comment.