1 path.module | path_form_element_validate($element, &$form_state, $complete_form) |
Form element validation handler for URL alias form element.
See also
File
- core/
modules/ path/ path.module, line 931 - Enables users to customize URLs and provide automatic URL alias patterns.
Code
function path_form_element_validate($element, &$form_state, $complete_form) {
if (!empty($form_state['values']['path']['alias'])) {
// Trim the submitted value.
$alias = trim($form_state['values']['path']['alias']);
form_set_value($element['alias'], $alias, $form_state);
// Node language needs special care. Since the language of the URL alias
// depends on the node language, and the node language can be switched
// right within the same form, we need to conditionally overload the
// originally assigned URL alias language.
if (isset($form_state['values']['langcode'])) {
form_set_value($element['langcode'], $form_state['values']['langcode'], $form_state);
}
$path = $form_state['values']['path'];
// Ensure that the submitted alias does not exist yet.
$existing_alias = path_is_alias_reserved($path['alias'], $path['source'], $path['langcode']);
if ($existing_alias) {
form_error($element, t('The alias is already in use.'));
}
}
}