function field_permissions_troubleshooting_form_validate in Field Permissions 6
Validate callback for the Field permissions troubleshooting form.
File
- includes/
admin.inc, line 341 - Administrative interface for the Field Permissions module.
Code
function field_permissions_troubleshooting_form_validate($form, &$form_state) {
if ($form_state['values']['op'] == t('Reset')) {
return;
}
// Validate the node.
$value = $form_state['values']['node'];
preg_match('`^(?:\\s*|(.*) )?\\[\\s*nid\\s*:\\s*([0-9]+)\\s*\\]\\s*$`', $value, $matches);
if (empty($matches)) {
// No explicit nid.
if (!($node = node_load(array(
'title' => $value,
)))) {
form_set_error('node', t('Node: found no valid post with that title.'));
return;
}
}
else {
// Explicit [nid:n].
list(, $title, $nid) = $matches;
if (($node = node_load($nid)) && !empty($title) && trim($title) != trim($node->title)) {
form_set_error('node', t('Node: title mismatch. Please check your selection.'));
return;
}
elseif (empty($node->nid)) {
form_set_error('node', t('Node: found no valid post with that title.'));
return;
}
}
$form_state['values']['nid'] = $node->nid;
// Validate the field against the node type.
if (!empty($form['options']['field'])) {
if (empty($form_state['values']['field'])) {
form_set_error('field', t('Field: please, select a field.'));
return;
}
else {
$content_type = content_types($node->type);
if (empty($content_type['fields'][$form_state['values']['field']])) {
form_set_error('field', t('Field: %field does not exist in the selected node type.', array(
'%field' => $form['options']['field']['#options'][$form_state['values']['field']],
)));
return;
}
}
}
// Validate the user.
if (!empty($form_state['values']['user'])) {
if (!($account = user_load(array(
'name' => $form_state['values']['user'],
)))) {
form_set_error('user', t('User: user %name cannot be found.', array(
'%name' => $form_state['values']['user'],
)));
return;
}
$form_state['values']['uid'] = $account->uid;
}
}