You are here

function og_panels_context_group_settings_form_validate in Organic groups 5

Same name and namespace in other branches
  1. 5.8 includes/groupcontext.inc \og_panels_context_group_settings_form_validate()
  2. 5.3 includes/groupcontext.inc \og_panels_context_group_settings_form_validate()
  3. 5.7 includes/groupcontext.inc \og_panels_context_group_settings_form_validate()
  4. 6 includes/og.panelscontext.inc \og_panels_context_group_settings_form_validate()

Validate a node.

1 string reference to 'og_panels_context_group_settings_form_validate'
og_panels_panels_contexts in ./og_panels.module
Implementation of hook_panels_contexts()

File

includes/groupcontext.inc, line 70
contexts/group.inc

Code

function og_panels_context_group_settings_form_validate($form, $form_values) {

  // Validate the autocomplete
  if (empty($form_values['external']) && empty($form_values['nid']) && empty($form_values['node'])) {
    form_error($form['node'], t('You must select a node.'));
    return;
  }
  if (empty($form_values['node'])) {
    return;
  }
  $nid = $form_values['node'];
  $preg_matches = array();
  $match = preg_match('/\\[nid: (\\d+)\\]/', $nid, $preg_matches);
  if (!$match) {
    $match = preg_match('/^nid: (\\d+)/', $nid, $preg_matches);
  }
  if ($match) {
    $nid = $preg_matches[1];
  }
  if (is_numeric($nid)) {
    $node = db_fetch_object(db_query(db_rewrite_sql("SELECT n.nid, n.type FROM {node} n WHERE n.nid = %d"), $nid));
  }
  else {
    $node = db_fetch_object(db_query(db_rewrite_sql("SELECT n.nid, n.type FROM {node} n WHERE LOWER(n.title) = LOWER('%s')"), $nid));
  }
  if (!$node) {
    form_error($form['node'], t('Invalid group selected.'));
  }
  elseif (!og_is_group_type($node->type)) {
    form_error($form['node'], t('Node is of type %type which not a group type.', array(
      '%type' => $node->type,
    )));
  }
  else {
    form_set_value($form['nid'], $node->nid);
  }
}