function content_multigroup_allowed_in in Content Construction Kit (CCK) 6.3
Helper function for deciding if a field is allowed into a Multigroup.
2 calls to content_multigroup_allowed_in()
- content_multigroup_field_basic_form in modules/
content_multigroup/ content_multigroup.admin.inc - Alter the basic field settings form.
- content_multigroup_field_overview_form_validate in modules/
content_multigroup/ content_multigroup.admin.inc - Validation for creating/moving fields and groups on the Manage Fields screen.
File
- modules/
content_multigroup/ content_multigroup.admin.inc, line 135 - Implementation of node type administration functions for content multigroup.
Code
function content_multigroup_allowed_in($field, $group) {
if ($group['group_type'] != 'multigroup') {
return array(
'allowed' => TRUE,
'message' => '',
);
}
// We can't allow fields with more multiple values than the group has
// to be moved into it.
$max_existing = content_max_delta($field['field_name']);
$group_multiple = $group['settings']['multigroup']['multiple'];
$multiple_values = content_multigroup_multiple_values();
if ($group_multiple != 1 && $max_existing > $group_multiple) {
return array(
'allowed' => FALSE,
'message' => t('This change is not allowed. The field %field already has %multiple values in the database but the group %group only allows %group_max. Making this change would result in the loss of data.', array(
'%field' => $field['widget']['label'],
'%multiple' => $max_existing,
'%group' => $group['label'],
'%group_max' => $multiple_values[$group_multiple],
)),
);
}
// Fields that handle their own multiple values may not have the same values
// in Multigroup fields and normal fields. We don't know if they will work or not.
// Adding a hook here where widgets that handle their own multiple values
// that will work correctly in Multigroups can allow their fields in.
if (content_handle('widget', 'multiple values', $field) != CONTENT_HANDLE_CORE) {
$allowed_widgets = array(
'optionwidgets_select',
'optionwidgets_buttons',
'optionwidgets_onoff',
'nodereference_buttons',
'nodereference_select',
'userreference_buttons',
'userreference_select',
);
$allowed_widgets = array_merge($allowed_widgets, module_invoke_all('content_multigroup_allowed_widgets'));
if (!in_array($field['widget']['type'], $allowed_widgets)) {
return array(
'allowed' => FALSE,
'message' => t('This change is not allowed. The field %field handles multiple values differently than the Content module. Making this change could result in the loss of data.', array(
'%field' => $field['widget']['label'],
)),
);
}
}
// Allow other modules to intervene.
// Any failure will prevent this action.
foreach (module_implements('content_multigroup_allowed_in') as $module) {
$function = $module . '_content_multigroup_allowed_in';
$result = $function($field, $group);
if ($result['allowed'] === FALSE) {
return array(
'allowed' => FALSE,
'message' => $result['message'],
);
}
}
$message = t('You are moving the field %field into a Multigroup.', array(
'%field' => $field['widget']['label'],
));
return array(
'allowed' => TRUE,
'message' => $message,
);
}