node_type_form_validate
modules/node/content_types.inc, строка 221
- Версии
- 5
node_type_form_validate(
$form_id,$form_values)- 6
node_type_form_validate($form, &$form_state)
Implementation of hook_form_validate()
.
Код
<?php
function node_type_form_validate($form_id, $form_values) {
$type = new stdClass();
$type->type = trim($form_values['type']);
$type->name = trim($form_values['name']);
// Work out what the type was before the user submitted this form
$old_type = trim($form_values['old_type']);
$types = node_get_types('names');
if (!$form_values['locked']) {
if (isset($types[$type->type]) && $type->type != $old_type) {
form_set_error('type', t('The machine-readable name %type is already taken.', array('%type' => $type->type)));
}
if (!preg_match('!^[a-z0-9_]+$!', $type->type)) {
form_set_error('type', t('The machine-readable name can only consist of lowercase letters, underscores, and numbers.'));
}
// 'theme' conflicts with theme_node_form()
// 'add' and 'list' conflict with menu paths
// '0' is invalid, since elsewhere we check it using empty().
if (in_array($type->type, array('0', 'theme', 'add', 'list'))) {
form_set_error('type', t("Invalid machine-readable name. Please enter a name other than %invalid.", array('%invalid' => $type->type)));
}
}
$names = array_flip($types);
if (isset($names[$type->name]) && $names[$type->name] != $old_type) {
form_set_error('name', t('The human-readable name %name is already taken.', array('%name' => $type->name)));
}
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии