domain_source_validate

Versions
6 – 7
domain_source_validate($form, &$form_state)

Form validation step

Code

contrib-6/domain/domain_source/domain_source.module, line 307

<?php
function domain_source_validate($form, &$form_state) {
  if ($form_state['values']['operation'] == 'domain') {
    ($form_state['values']['domain_source'] == 0) ? $key = -1 : $key = $form_state['values']['domain_source'];
    if ($form_state['values']['domain_site'] && $key == -1 || $key == DOMAIN_SOURCE_USE_ACTIVE) {
      // These cases are acceptable, so we let them pass.
      // I find this code easier to read than a compound negative IF statement.
    }
    else if ($key == DOMAIN_SOURCE_IGNORE) {
      // In this case, we need to check all the selected nodes, which is resource intensive.
      $nodes = array_filter($form_state['values']['nodes']);
      foreach ($nodes as $nid) {
        $source = domain_source_lookup($nid);
        $key = ($source['domain_id'] == 0) ? -1 : $source['domain_id'];
        // Test for the first two behaviors, which add domains to the node.
        $behavior = $form_state['values']['behavior'];
        if ($behavior < 2) {
          if (empty($form_state['values']['domains'][$key])) {
            $node = node_load($nid);
            form_set_error('domain_source', t('The source affiliate must be selected as a publishing option. %title is assigned to %domain.', array('%title' => $node->title, '%domain' => $source['sitename'])));
          }
        }
        // Do not allow removal of the source domain when removing domains from the node.
        else if (!empty($form_state['values']['domains'][$key])) {
          $node = node_load($nid);
          form_set_error('domain_source', t('The source affiliate must be selected as a publishing option. %title is assigned to %domain.', array('%title' => $node->title, '%domain' => $source['sitename'])));
        }
      }
    }
    // The source domain must have been selected.
    else if (empty($form_state['values']['domains'][$key])) {
      form_set_error('domain_source', t('The source affiliate must be selected as a publishing option.'));
    }
  }
}
?>

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options