function views_ui_add_item_form
Same name in other branches
- 7.x-3.x includes/admin.inc \views_ui_add_item_form()
Form to add_item items in the views UI.
1 string reference to 'views_ui_add_item_form'
- views_ui_ajax_forms in includes/
admin.inc
File
-
includes/
admin.inc, line 3010
Code
function views_ui_add_item_form(&$form_state) {
$view =& $form_state['view'];
$display_id = $form_state['display_id'];
$type = $form_state['type'];
if (!$view->set_display($display_id)) {
views_ajax_render(t('Invalid display id @display', array(
'@display' => $display_id,
)));
}
$display =& $view->display[$display_id];
$types = views_object_types();
$ltitle = $types[$type]['ltitle'];
if (!empty($types[$type]['type'])) {
$type = $types[$type]['type'];
}
$form['#title'] = check_plain($display->display_title) . ': ';
$form['#title'] .= t('Add @type', array(
'@type' => $ltitle,
));
$form['#section'] = $display_id . 'add-item';
// Figure out all the base tables allowed based upon what the relationships provide.
$base_tables = $view->get_base_tables();
$options = views_fetch_fields(array_keys($base_tables), $type, $display->handler
->use_group_by());
if (!empty($options)) {
$groups = array(
'all' => t('- All -'),
);
$form['group'] = array(
'#type' => 'select',
'#title' => t('Groups'),
'#options' => array(),
'#attributes' => array(
'class' => 'views-master-dependent',
),
);
$form['name'] = array(
'#prefix' => '<div class="views-radio-box form-checkboxes">',
'#suffix' => '</div>',
'#tree' => TRUE,
'#default_value' => 'all',
);
// Group options first to simplify the DOM objects that Views
// dependent JS will act upon.
$grouped_options = array();
foreach ($options as $key => $option) {
$group = preg_replace('/[^a-z0-9]/', '-', strtolower($option['group']));
$groups[$group] = $option['group'];
$grouped_options[$group][$key] = $option;
}
foreach ($grouped_options as $group => $group_options) {
$form['name'][$group . '_start'] = array(
'#type' => 'markup',
'#value' => '<div class="views-dependent-all views-dependent-' . $group . '">',
);
foreach ($group_options as $key => $option) {
$form['name'][$key] = array(
'#type' => 'checkbox',
'#title' => t('!group: !field', array(
'!group' => $option['group'],
'!field' => $option['title'],
)),
'#description' => $option['help'],
'#return_value' => $key,
);
}
$form['name'][$group . '_end'] = array(
'#type' => 'markup',
'#value' => '</div>',
);
}
$form['group']['#options'] = $groups;
}
else {
$form['markup'] = array(
'#value' => '<div class="form-item">' . t('There are no @types available to add.', array(
'@types' => $ltitle,
)) . '</div>',
);
}
views_ui_standard_form_buttons($form, $form_state, 'views_ui_add_item_form', t('Add'));
return $form;
}