You are here

function site_disclaimer_admin_settings_validate in Site Disclaimer 7

Same name and namespace in other branches
  1. 6 site_disclaimer.admin.inc \site_disclaimer_admin_settings_validate()

Validate the site_disclaimer_admin_settings form.

See also

site_disclaimer_admin_settings()

File

./site_disclaimer.admin.inc, line 287
Administration settings for Site Disclaimer module.

Code

function site_disclaimer_admin_settings_validate($form, &$form_state) {
  _site_disclaimer_admin_decode_settings($form_state, TRUE);

  // Validate form only in case of settings save
  if ($form_state['#site_disclaimer_mode_switch']) {
    return;
  }

  // Check if settings require node id (for @link)
  $checkbox_label = filter_xss_admin($form_state['values']['site_disclaimer_checkbox_label']);
  $use_link = strpos($checkbox_label, '@link') !== FALSE;
  $use_named_links = strpos($checkbox_label, '@"') !== FALSE;

  // Validate named links in 'site_disclaimer_checkbox_label'
  $output = _site_disclaimer_checkbox_label_substitute_links($checkbox_label, $linked_nodes, $linked_errors);
  foreach ($linked_errors as $titla => $error) {
    form_set_error('site_disclaimer_checkbox_label', $error);
  }
  $form_state['#site_disclaimer_named_links'] = $linked_nodes;

  // Save for site_disclaimer_admin_settings_submit() handler
  // Validate $use_link and 'site_disclaimer_node_id'/'site_disclaimer_node_title'
  // Set message about Site Disclaimer configuration
  if ($form_state['#site_disclaimer_mode'] = 'node_id') {
    if (empty($form_state['values']['site_disclaimer_node_id'])) {

      // Empty means "disabled", unless @link is set
      if ($use_link) {
        form_set_error('site_disclaimer_node_id', t('You used @link token. You must specify a node <em>nid</em>.'));
      }
      else {
        drupal_set_message($use_named_links ? t('Site Disclaimer will use links in the checkbox.') : t('Site Disclaimer disabled.'));
      }
    }
  }
  elseif (empty($form_state['values']['site_disclaimer_node_title'])) {

    // Empty means "disabled", unless @link is set
    if ($use_link) {
      form_set_error('site_disclaimer_node_title', t('You used @link token. You must specify a node title.'));
    }
    else {
      drupal_set_message($use_named_links ? t('Site Disclaimer will use links in the checkbox.') : t('Site Disclaimer disabled.'));
    }
  }
}