You are here

function site_disclaimer_form_user_register_alter in Site Disclaimer 6

Implementation of hook_form_form_id_alter().

2 calls to site_disclaimer_form_user_register_alter()
site_disclaimer_admin_settings in ./site_disclaimer.admin.inc
Menu callback; show settings form.
site_disclaimer_confirm in ./site_disclaimer.pages.inc
Display the Site Disclaimer, when a user needs to confirm them after registering.

File

./site_disclaimer.module, line 153
This module adds Site Disclaimer to the registration page.

Code

function site_disclaimer_form_user_register_alter(&$form, $form_state, $langcode = NULL, $preview = FALSE) {
  $args = isset($form['#parameters']) ? $form['#parameters'] : array(
    '',
  );
  $form_id = array_shift($args);

  // Administrative users can skip site_disclaimer on admin/user/user/create page.
  if (user_access('administer users') && !$preview && $form_id == 'user_register') {
    return;
  }
  $height = variable_get('site_disclaimer_node_height', '');
  if ($height) {
    $css = '#site-disclaimer { height:' . check_plain($height) . '; overflow:auto; }';

    // Revert the styling so print shows the full text.
    $css2 = '#site-disclaimer { height:auto; overflow:visible; }';
    drupal_set_html_head('<style type="text/css">' . $css . '</style>');
    drupal_set_html_head('<style type="text/css" media="print">' . $css2 . '</style>');
  }

  // Getting the node that contains the Site Disclaimer.
  $nid = _site_disclaimer_nid_translated(variable_get('site_disclaimer_node_id', ''));
  $node = NULL;
  if (!empty($nid)) {
    $node = node_load($nid);
    if (empty($node)) {
      watchdog('Site Disclaimer', 'The Site Disclaimer node !nid could not be loaded. Please check the settings and the node.', array(
        '!nid' => $nid,
      ), WATCHDOG_ALERT, l(t('Administer Site Disclaimer'), SITE_DISCLAIMER_SETTINGS_PATH));
    }
  }

  // Will we show the full text of the Terms or only provide a link to the Terms.
  // Reading the checkbox label to find out.
  $checkbox_label = filter_xss_admin(variable_get('site_disclaimer_checkbox_label', SITE_DISCLAIMER_DEFAULT_CHECKBOX_LABEL));
  $use_link = strpos($checkbox_label, '@link') !== FALSE;
  $use_named_links = strpos($checkbox_label, '@&quot;') !== FALSE;
  $show_node = $node && !$use_link && !$use_named_links;

  // If there is no node to show and no links in the $checkbox_label, we don't show the terms form.
  // Same logic as in _site_disclaimer_enabled()
  if (!$use_link && !$use_named_links && !$node) {
    return;
  }
  $checkbox_label = theme('site_disclaimer_checkbox_label', $checkbox_label, $node);
  $fieldset_en = variable_get('site_disclaimer_fieldset', 1);
  if ($fieldset_en) {

    // Adding the fieldset.
    $form['site_disclaimer'] = array(
      '#type' => 'fieldset',
      '#title' => check_plain(variable_get('site_disclaimer_title', SITE_DISCLAIMER_DEFAULT_TITLE)),
      '#weight' => 10,
    );
    $fieldset =& $form['site_disclaimer'];
  }
  else {
    $fieldset =& $form;
  }

  // Adding the Site Disclaimer to the fieldset.
  if ($show_node) {
    $node = node_prepare($node);
    if (!empty($node->body)) {
      $fieldset['site_disclaimer_text'] = array(
        '#value' => theme('site_disclaimer', $node->body, $node),
        '#weight' => 9,
      );
    }
    else {
      watchdog('Site Disclaimer', 'The body field of the Site Disclaimer node !nid is empty. Please check the the node content.', array(
        '!nid' => $nid,
      ), WATCHDOG_ALERT, l(t('Administer Site Disclaimer'), SITE_DISCLAIMER_SETTINGS_PATH));
    }
  }

  // Adding the checkbox to the fieldset.
  $fieldset['I_agree'] = array(
    '#type' => 'checkbox',
    '#title' => $checkbox_label,
    '#required' => TRUE,
    // The following adds "required" validation to the checkbox (patches core missing functionality as of D6.16)
    '#element_validate' => array(
      '_site_disclaimer_validate_checkbox',
    ),
    '#return_value' => variable_get('site_disclaimer_version', 1),
    '#weight' => 10,
  );
  return $form;
}