You are here

function readonlymode_form_system_site_maintenance_settings_alter in Read only mode 6

Implementation of hook_form_FORM_ID_alter(). Alter the Site Maintenance form

File

./readonlymode.module, line 65
Read Only Mode provides an alternate 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 new content while…

Code

function readonlymode_form_system_site_maintenance_settings_alter(&$form, $form_state) {
  $form['read_only'] = array(
    '#title' => t('Read Only Mode'),
    '#type' => 'fieldset',
    '#weight' => 0,
    '#collapsible' => TRUE,
    '#collapsed' => variable_get('site_readonly', FALSE) ? FALSE : TRUE,
  );
  $form['read_only']['site_readonly'] = array(
    '#type' => 'checkbox',
    '#title' => t('Read only mode'),
    '#description' => t('Put the site in read-only mode. When set to "Read-only", all content moderation (add/edit) will be impossible.'),
    '#weight' => 0,
    '#default_value' => variable_get('site_readonly', FALSE),
  );

  // Message configuration is in a collapsed fieldset so that it doesn't clutter the display.
  $form['read_only']['messages'] = array(
    '#title' => t('Messages and redirects'),
    '#type' => 'fieldset',
    '#description' => t('Configure the redirect URL and messages to display to users while the site is in Read Only Mode.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['read_only']['messages']['site_readonly_message'] = array(
    '#type' => 'textarea',
    '#title' => t('Read Only Mode warning'),
    '#description' => t('This warning will be displayed when viewing a page that has a blocked form while in Read Only Mode.'),
    '#default_value' => _readonlymode_notice(),
    '#rows' => 3,
    '#required' => TRUE,
  );
  $form['read_only']['messages']['site_readonly_message_form_not_saved'] = array(
    '#type' => 'textarea',
    '#title' => t('Form submission error'),
    '#description' => t('This error will be displayed when a blocked form is submitted while in Read Only Mode. This scenario occurs when a user starts filling out a form during normal site operation and then attempts to submit the form after Read Only Mode has been enabled.'),
    '#default_value' => _readonlymode_notice_form_not_saved(),
    '#rows' => 3,
    '#required' => TRUE,
  );
  $form['read_only']['messages']['site_readonly_url'] = array(
    '#type' => 'textfield',
    '#title' => t('Redirect path'),
    '#description' => t('When given, Drupal will redirect the user to this URL when a user tries to add/edit content instead of displaying the message above.'),
    '#default_value' => variable_get('site_readonly_url', ''),
  );

  // Allowed forms configuration is in a collapsed fieldset so that it doesn't clutter the display.
  $form['read_only']['forms'] = array(
    '#title' => t('Allowed forms'),
    '#type' => 'fieldset',
    '#description' => t('Configure which forms will be exempt from restriction when in read-only mode.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['read_only']['forms']['site_readonly_forms_allowed'] = array(
    '#type' => 'textarea',
    '#title' => t('Forms that can be submitted'),
    '#description' => t("These forms are not restricted when in read only mode. Enter one form id per line. You may use the wildcard character '*' to use loose matches. For example: webform* will match all webforms. Note that the following forms will always be allowed: %allowed_forms.", array(
      '%allowed_forms' => implode(', ', _readonlymode_default_forms_allowed()),
    )),
    '#default_value' => variable_get('site_readonly_forms_allowed', ''),
  );
  $form['read_only']['forms']['site_readonly_forms_viewonly'] = array(
    '#type' => 'textarea',
    '#title' => t('Forms that can be viewed'),
    '#description' => t("These forms are allowed to be viewed but will not accept form submissions. Enter one form id per line. You may use the wildcard character '*' to use loose matches. For example: webform* will match all webforms. Note that the following forms will always be allowed: %allowed_forms.", array(
      '%allowed_forms' => implode(', ', _readonlymode_default_forms_viewonly()),
    )),
    '#default_value' => variable_get('site_readonly_forms_viewonly', ''),
  );
  $form['#validate'][] = 'readonlymode_form_validate_url';
}