You are here

function ccl_actions_form_validate in Custom Contextual Links 8

Same name and namespace in other branches
  1. 7 ccl_actions/ccl_actions.module \ccl_actions_form_validate()

Validafion handler for ccl_actions_form().

See also

ccl_actions_form()

File

ccl_actions/ccl_actions.module, line 148
Implementation of core actions for CCL.

Code

function ccl_actions_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['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.'));
    }
  }
}