You are here

function ccl_add_form_validate in Custom Contextual Links 8

Same name and namespace in other branches
  1. 7 ccl.admin.inc \ccl_add_form_validate()

Validafion handler for ccl_add_form().

See also

ccl_add_form()

File

./ccl.admin.inc, line 296
Provides administrative functions for ccl.

Code

function ccl_add_form_validate($form, &$form_state) {
  $values = $form_state['values'];

  // Check that that we can get the node id and transform it for saving.
  if ($values['ccl_type'] == 'node' && $values['node_options'] == 'node') {
    if (is_numeric($values['node_id'])) {
      $form_state
        ->setValueForElement($form['options_group']['node_id'], $values['node_id']);
    }
    elseif (preg_match('/\\[nid:[0-9]*\\]/', $values['node_id'], $match)) {
      $form_state
        ->setValueForElement($form['options_group']['node_id'], substr(rtrim($match[0], ']'), 5));
    }
    else {
      form_set_error('nid', t('Enter a node id or use the autocomplete widget to select an existing node.'));
    }
  }
}