You are here

function readonlymode_form_alter in Read only mode 6

Same name and namespace in other branches
  1. 8 readonlymode.module \readonlymode_form_alter()
  2. 7 readonlymode.module \readonlymode_form_alter()

Implementation of hook_form_alter(). Permit posting of content

File

./readonlymode.module, line 28
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_alter(&$form, $form_state, $form_id) {
  if (!_readonlymode_form_check($form, $form['form_id']['#value'], FALSE)) {

    // Check whether the form is a fresh form being served to the user.
    if (!isset($form_state['input']['form_token'])) {

      // If a redirect URL is set, then we redirect to it.
      if ($url = variable_get('site_readonly_url', '')) {
        drupal_goto($url);
      }
      else {

        // Remove FAPI #after_build handlers.
        $form['#after_build'] = array();

        // Remove all elements of the form.
        foreach (element_children($form) as $key) {
          if (!in_array($key, array(
            'form_id',
            'form_token',
            'form_build_id',
          ))) {
            unset($form[$key]);
          }
        }
        $form['readonly_notice'] = array(
          '#value' => _readonlymode_notice(),
          '#prefix' => '<div class="messages warning">',
          '#suffix' => '</div>',
        );
      }
    }
  }
  if (user_access('readonlymode access forms') && variable_get('site_readonly', FALSE)) {
    drupal_set_message(t('The site is currently set to read-only, content moderation is disabled for all users without the "readonlymode access forms" permission.'), 'warning', FALSE);
  }
  $form['#validate'][] = 'readonlymode_check_form_validate';
}