function og_ui_field_settings_validate in Organic groups 7
Same name and namespace in other branches
- 7.2 og_ui/og_ui.admin.inc \og_ui_field_settings_validate()
File
- og_ui/
og_ui.admin.inc, line 775 - Admin settings for Organic groups module.
Code
function og_ui_field_settings_validate($form, &$form_state) {
$bundle = preg_replace('/^.*__/i', '', $form_state['values']['bundles']);
$entity_type = str_replace('__' . $bundle, '', $form_state['values']['bundles']);
// Check if field can be attached to entity.
$group_field = og_fields_info($form_state['values']['fields']);
$bundles = field_info_bundles($entity_type);
$entity_info = entity_get_info($entity_type);
$params = array(
'%field' => $group_field['instance']['label'],
'%bundle' => $bundles[$bundle]['label'],
'%entity' => $entity_info['label'],
);
if ($form_state['values']['fields'] == OG_GROUP_FIELD && $entity_type == 'group') {
form_set_error('bundles', t('It is not allowed to add the group field to the group entity.'));
}
// Check if field doesn't exist already.
if (($field = field_info_field($form_state['values']['fields'])) && !empty($field['bundles'][$entity_type]) && in_array($bundle, drupal_map_assoc($field['bundles'][$entity_type]))) {
form_set_error('bundles', t('Field %field already exists in %bundle.', $params));
}
// Check field can be attached to entity type.
if (!empty($group_field['entity']) && !in_array($entity_type, $group_field['entity'])) {
$items = array();
foreach ($group_field['entity'] as $entity_type) {
$info = entity_get_info($entity_type);
$items[] = $info['label'];
}
form_set_error('bundles', t('Field %field can only be attached to %entities entity bundles.', $params + array(
'%entities' => implode(', ', $items),
)));
}
}