function fieldgroup_validate_name in Content Construction Kit (CCK) 6.2
Same name and namespace in other branches
- 6.3 modules/fieldgroup/fieldgroup.module \fieldgroup_validate_name()
API for group name validation.
Pulled into separate function to be re-usable.
1 call to fieldgroup_validate_name()
- fieldgroup_field_overview_form_validate in modules/
fieldgroup/ fieldgroup.module
File
- modules/
fieldgroup/ fieldgroup.module, line 372 - Create field groups for CCK fields.
Code
function fieldgroup_validate_name($group, $type_name) {
$errors = array();
// No label.
if (!$group['label']) {
$errors['label'][] = t('You need to provide a label.');
}
// No group name.
if (!$group['group_name']) {
$errors['group_name'][] = t('You need to provide a group name.');
}
else {
$group_name = $group['group_name'];
$group['group_type'] = !empty($group['group_type']) ? $group['group_type'] : 'standard';
// Add the 'group_' prefix.
if (substr($group_name, 0, 6) != 'group_') {
$group_name = 'group_' . $group_name;
}
// Invalid field name.
if (!preg_match('!^group_[a-z0-9_]+$!', $group_name)) {
$errors['group_name'][] = t('The group name %group_name is invalid. The name must include only lowercase unaccentuated letters, numbers, and underscores.', array(
'%group_name' => $group_name,
));
}
if (strlen($group_name) > 32) {
$errors['group_name'][] = t('The group name %group_name is too long. The name is limited to 32 characters, including the \'group_\' prefix.', array(
'%group_name' => $group_name,
));
}
// Group name already exists.
$groups = fieldgroup_groups($type_name);
if (isset($groups[$group_name])) {
$errors['group_name'][] = t('The group name %group_name already exists.', array(
'%group_name' => $group_name,
));
}
if (empty($errors['group_name'])) {
$group['group_name'] = $group_name;
}
}
return array(
'group_name' => $group['group_name'],
'errors' => $errors,
);
}