function custom_pub_add_validate in Custom Publishing Options 7
Same name and namespace in other branches
- 6 custom_pub.module \custom_pub_add_validate()
Validate handler
_state
Parameters
$form:
File
- ./
custom_pub.admin.inc, line 108 - Admin functions.
Code
function custom_pub_add_validate($form, &$form_state) {
$types = variable_get('custom_pub_types', array());
$type = array();
$type['type'] = trim($form_state['values']['state_machine']);
$type['name'] = trim($form_state['values']['state']);
$node = drupal_get_schema('node');
if (isset($types[$type['type']])) {
form_set_error('state_machine', t('The machine-readable name %type is already taken.', array(
'%type' => $type->type,
)));
}
if (!preg_match('!^[a-z0-9_]+$!', $type['type'])) {
form_set_error('state_machine', t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
}
// 'theme' conflicts with theme_node_form().
// '0' is invalid, since elsewhere we check it using empty().
if (in_array($type['type'], array_keys($node['fields'])) && !isset($types[$type['type']])) {
form_set_error('state_machine', t("Invalid machine-readable name. That name is already taken by a database column. Please enter a name other than %invalid.", array(
'%invalid' => $type['type'],
)));
}
foreach ($types as $check) {
if ($type['name'] == $check['name']) {
form_set_error('state', t("Invalid Label. That Publishing Label is already taken. Please enter a label other than %invalid.", array(
'%invalid' => $type['name'],
)));
}
}
}