function pathauto_patterns_validate in Patterns 7
Same name and namespace in other branches
- 7.2 patterns_components/components/pathauto.inc \pathauto_patterns_validate()
File
- patterns_components/
components/ pathauto.inc, line 111
Code
function pathauto_patterns_validate($action, $tag, &$data = NULL) {
$status = PATTERNS_SUCCESS;
$msg = '';
if ($tag == 'url_alias' && ($action == PATTERNS_MODIFY || $action == PATTERNS_DELETE)) {
if (!isset($data['pid'])) {
$status = PATTERNS_ERR;
$msg = t('Attempt to %update a nonexistent url alias.', array(
'%update' => $action,
));
}
else {
$exist = db_query("SELECT COUNT(*) FROM {url_alias} WHERE pid = :pid", array(
'pid' => $data['pid'],
))
->fetchField();
// TODO: count()
if (!$exist) {
$status = PATTERNS_ERR;
$msg = t('Attempt to %update a nonexistent url alias.', array(
'%update' => $action,
));
}
}
}
elseif ($tag == 'url_alias' && $action == PATTERNS_CREATE) {
$lan = isset($data['language']) ? $data['language'] : 'und';
$exist = db_query("SELECT COUNT(*) FROM {url_alias} WHERE alias = :name and language = :lan", array(
'name' => $data['alias'],
'lan' => $lan,
))
->fetchField();
// TODO: count()
if ($exist) {
$status = PATTERNS_ERR;
$msg = t('The alias %path is already in use in this language.', array(
'%path' => $data['alias'],
));
}
}
return patterns_results($status, $msg);
}