function _readonlymode_form_check in Read only mode 8
Same name and namespace in other branches
- 6 readonlymode.module \_readonlymode_form_check()
- 7 readonlymode.module \_readonlymode_form_check()
Helper function to check form submissions.
Internal handler to check whether this form is to be restricted.
Parameters
array $form: The full form.
string $form_id: The form ID.
bool $submitted: Defaults to TRUE.
Return value
bool TRUE when matched, FALSE otherwise.
2 calls to _readonlymode_form_check()
- readonlymode_check_form_validate in ./
readonlymode.module - Validation handler for all form submissions.
- readonlymode_form_alter in ./
readonlymode.module - Implements hook_form_alter().
File
- ./
readonlymode.module, line 204 - Read Only Mode provides an alternative to the built in 'Maintenance Mode' in Drupal. Instead of displaying a static text file to users while the site is in maintenance mode, Read Only Mode will allow access (reading) of existing content…
Code
function _readonlymode_form_check(array &$form, $form_id, $submitted = TRUE) {
$settings = \Drupal::config('readonlymode.settings');
// If not in Read Only Mode, allow the form.
if (!$settings
->get('enabled')) {
return TRUE;
}
// Admins can access all forms.
if (\Drupal::currentUser()
->hasPermission('readonlymode access forms')) {
return TRUE;
}
// Is the form in the list of default forms? Then allow access.
if (in_array($form_id, $settings
->get('forms.default.edit'))) {
return TRUE;
}
// Is the form in the list of read-only forms? Then allow access.
if (!$submitted && in_array($form_id, $settings
->get('forms.default.view'))) {
return TRUE;
}
// Check if the form is in the custom list of allowed forms. If so, allow.
if (_readonlymode_form_list_check($form_id, $settings
->get('forms.additional.edit'))) {
return TRUE;
}
// Check if the form is in the custom list of allowed read-only forms.
if (!$submitted && _readonlymode_form_list_check($form_id, $settings
->get('forms.additional.view'))) {
return TRUE;
}
return FALSE;
}