How to control path alias in custom node form #validate function? To change form values in code, I understand that the right way is to add a validate function with hook_form_alter, to append the function's name to the #validate array then use form_set_value.

When I inspect the form array at this point though, I cannot see a way to reliably determine the parents of the path value.

e.g. I have

$form_state['groups']['additional_settings'][4]['alias']


And I can only assume that the 4 index is not always going to be 4; that it might be a different number if more modules are installed etc.

So how can I set the alias? (I also need to un-set pathauto's checkbox so it does not auto-generate a new path.) Am I doing it in the right place?

Thanks.
You will find the values submitted by the user in $form_state['values]. So you can just fetch the ones submitted alter them and them send them back to the form. And the path settings are located at $form['path']. $form_state['groups'] is just a way of grouping form elements together.

/**
 * Implements hook_node_form_FORM_ID_alter().
 */
function MYMODULE_form_node_form_alter(&amp;$form, &amp;$form_state) {
  // Add our validate function to all node forms.
  $form['#validate'][] = 'MYMODULE_alter_node_path';
}

/**
 * Custom form validate function.
 */
function MYMODULE_alter_node_path($form, &amp;$form_state) {
  // Fetch the path values submitted.
  $value = $form_state['values']['path'];
  // Do your changes to the path and unset pathauto checkbox.
  $value['alias'] = 'new-alias';
  $value['pathauto'] = FALSE;
  // Set the values in the form.
  form_set_value($form['path'], $value, $form_state);
}