| 1 field_group.field_ui.inc | field_group_field_overview_validate(array $form, array &$form_state) |
Validate handler for the overview screens.
Parameters
array $form: An associative array containing the structure of the form.
array $form_state: The state of the form.
File
- core/
modules/ field_group/ field_group.field_ui.inc, line 702 - Field_group.field_ui.inc is a file that contains most functions needed on the Fields UI Manage forms (display and fields).
Code
function field_group_field_overview_validate(array $form, array &$form_state) {
$form_values = $form_state['values']['fields'];
$entity_type = $form['#entity_type'];
$bundle = $form['#bundle'];
$mode = (isset($form['#view_mode']) ? $form['#view_mode'] : 'form');
$group = $form_values['_add_new_group'];
// Validate if any information was provided in the 'add new group' row.
if (array_filter(array($group['label'], $group['group_name']))) {
// Missing group name.
if (!$group['group_name']) {
form_set_error('fields][_add_new_group][group_name', t('Add new group: you need to provide a group name.'));
}
// Group name validation.
else {
$group_name = $group['group_name'];
// Add the 'group_' prefix.
if (backdrop_substr($group_name, 0, 6) != 'group_') {
$group_name = 'group_' . $group_name;
form_set_value($form['fields']['_add_new_group']['group_name'], $group_name, $form_state);
}
// Invalid group name.
if (!preg_match('!^group_[a-z0-9_]+$!', $group_name)) {
form_set_error('fields][_add_new_group][group_name', t('Add new group: the group name %group_name is invalid. The name must include only lowercase unaccentuated letters, numbers, and underscores.', array('%group_name' => $group_name)));
}
if (backdrop_strlen($group_name) > 32) {
form_set_error('fields][_add_new_group][group_name', t("Add new group: 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.
if (field_group_exists($group_name, $entity_type, $bundle, $mode)) {
form_set_error('fields][_add_new_group][group_name', t('Add new group: the group name %group_name already exists.', array('%group_name' => $group_name)));
}
}
}
}