function node_patterns_validate in Patterns 7
Same name and namespace in other branches
- 7.2 patterns_components/components/node.inc \node_patterns_validate()
File
- patterns_components/
components/ node.inc, line 158
Code
function node_patterns_validate($action, $tag, &$data) {
$status = PATTERNS_SUCCESS;
$msg = '';
$result = NULL;
if ($tag == 'node') {
if ($action !== PATTERNS_CREATE) {
$data['node'] = node_load($data['nid']);
if ($data['node'] === FALSE) {
$status = PATTERNS_ERR;
$msg = t('Cannot modify or delete a nonexistent Node.');
}
else {
$data['node'] = (object) $data['node'];
if ($action === PATTERNS_MODIFY && $data['type'] != $data['node']->type) {
$status = PATTERNS_ERR;
$msg = t("You can't change content type for already existing node.");
}
}
}
if (empty($data['type']) && $action === PATTERNS_CREATE) {
$status = PATTERNS_ERR;
$msg = t('"type" field is required.');
}
elseif ($action === PATTERNS_DELETE && empty($data['nid'])) {
$status = PATTERNS_ERR;
$msg = t('"id" field is required.');
}
// TODO: validate name field - should be valid/existing username
}
elseif ($tag == 'content_type') {
// TODO: check required fields for content types
}
return patterns_results($status, $msg, $result);
}