function og_ui_field_settings in Organic groups 7
Same name and namespace in other branches
- 7.2 og_ui/og_ui.admin.inc \og_ui_field_settings()
Groups permissions on default settings form.
Allow site admin to add or remove group fields from fieldable enteies.
1 string reference to 'og_ui_field_settings'
- og_ui_menu in og_ui/
og_ui.module - Implements hook_menu().
File
- og_ui/
og_ui.admin.inc, line 675 - Admin settings for Organic groups module.
Code
function og_ui_field_settings($form, &$form_state) {
$form = array();
$options = array();
$options = array();
foreach (entity_get_info() as $entity_type => $entity) {
if (!empty($entity['fieldable']) && $entity_type != 'group') {
foreach ($entity['bundles'] as $bundle_name => $bundle) {
// Prefix the bundle name with the entity type.
$options[$entity_type][$entity_type . '__' . $bundle_name] = check_plain($bundle['label']);
}
}
}
$form['bundles'] = array(
'#title' => t('Bundles'),
'#type' => 'select',
'#options' => $options,
);
$options = array();
foreach (og_fields_info() as $field_name => $field) {
foreach ($field['type'] as $type) {
$options[$type][$field_name] = filter_xss($field['instance']['label']);
}
}
$form['fields'] = array(
'#title' => t('Fields'),
'#type' => 'select',
'#options' => $options,
);
$field_enabled = array();
$group_fields = og_fields_info();
$group_fields_name = array_keys($group_fields);
$entity_info = entity_get_info();
// Get the fields that exist in the bundle.
foreach (field_info_fields() as $field_name => $field) {
if (in_array($field_name, $group_fields_name) && !empty($field['bundles'])) {
foreach ($field['bundles'] as $entity_type => $bundles) {
foreach ($bundles as $bundle) {
$field_enabled[$entity_type][$bundle][] = $field_name;
}
}
}
}
if ($field_enabled) {
$form['group_fields'] = array(
'#type' => 'vertical_tabs',
'#weight' => 99,
);
// Show all the group fields of each bundle.
foreach ($field_enabled as $entity_type => $bundles) {
foreach ($bundles as $bundle => $fields) {
$options = array();
$bundles = field_info_bundles($entity_type);
$form['group_fields_' . $entity_type . '_' . $bundle] = array(
'#type' => 'fieldset',
'#title' => t('@bundle - @entity entity', array(
'@bundle' => $bundles[$bundle]['label'],
'@entity' => $entity_info[$entity_type]['label'],
)),
'#collapsible' => TRUE,
'#group' => 'group_fields',
);
foreach ($fields as $field_name) {
$options[] = array(
check_plain($group_fields[$field_name]['instance']['label']),
filter_xss($group_fields[$field_name]['description']),
l(t('Delete'), "admin/config/group/fields/{$entity_type}/{$bundle}/{$field_name}/delete"),
);
}
$header = array(
t('Field'),
t('Description'),
t('Operations'),
);
$form['group_fields_' . $entity_type . '_' . $bundle]['fields'] = array(
'#markup' => theme('table', array(
'header' => $header,
'rows' => $options,
)),
);
}
}
}
else {
$form['group_fields'] = array(
'#markup' => t('There are no Group fields attached to any bundle yet.'),
);
}
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Add field'),
);
return $form;
}