You are here

function domain_source_validate in Domain Access 7.2

Same name and namespace in other branches
  1. 5 domain_source/domain_source.module \domain_source_validate()
  2. 6.2 domain_source/domain_source.module \domain_source_validate()
  3. 7.3 domain_source/domain_source.module \domain_source_validate()

Form validation step

1 string reference to 'domain_source_validate'
domain_source_form_domain_content_admin_alter in domain_source/domain_source.module
Integrate with Domain Content.

File

domain_source/domain_source.module, line 385
Creates a source domain for linking to content from other domains.

Code

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.
    }
    elseif ($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, array(), $form_state['values']['domain_site'], TRUE);
        $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'],
            )));
          }
        }
        elseif (!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'],
          )));
        }
      }
    }
    elseif (empty($form_state['values']['domains'][$key])) {
      form_set_error('domain_source', t('The source affiliate must be selected as a publishing option.'));
    }
  }
}