Commit 25090dbe authored by Katherine Senzee's avatar Katherine Senzee

Move field options form items into fieldsets for better UX.

parent dd50052c
......@@ -335,24 +335,13 @@ class views_handler_field extends views_handler {
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
// Use prefix and suffix to fake a fieldset because we use #tree.
$form['style_prefix'] = array(
'#value' => '<fieldset id="views-validator-options"><legend>' . t('Style settings') . '</legend>',
);
$form['exclude'] = array(
'#type' => 'checkbox',
'#title' => t('Exclude from display'),
'#default_value' => $this->options['exclude'],
'#description' => t('Check this box to not display this field, but still load it in the view. Use this option to not show a grouping field in each record, or when doing advanced theming, or when you want to use this field as a token in other fields.'),
);
$form['element_type'] = array(
'#title' => t('HTML element'),
'#options' => $this->get_elements(),
'#type' => 'select',
'#default_value' => $this->options['element_type'],
'#description' => t('Most styles provide wrappers for fields. If the chosen style supports wrappers, wrap the field in this HTML element. The default will usually be either DIV or SPAN.'),
'#fieldset' => 'style_settings',
);
$form['element_class'] = array(
......@@ -360,13 +349,34 @@ class views_handler_field extends views_handler {
'#description' => t('The class to provide on the wrapper element. You may enter data from this view as per the "Replacement patterns" used in "Rewrite the output of this field".'),
'#type' => 'textfield',
'#default_value' => $this->options['element_class'],
'#fieldset' => 'style_settings',
);
$form['custom_label'] = array(
'#type' => 'checkbox',
'#title' => t('Create a label'),
'#description' => t('Enable to create a custom label for this field.'),
'#default_value' => (bool) ($this->definition['title'] !== $this->label()),
);
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
'#default_value' => isset($this->options['label']) ? $this->options['label'] : '',
'#description' => t('The label for this field that will be displayed to end users if the style requires it.'),
'#process' => array('ctools_dependent_process'),
'#dependency' => array(
'edit-options-custom-label' => array(1)
),
);
$form['element_label_colon'] = array(
'#type' => 'checkbox',
'#title' => t('Place a colon after the label'),
'#default_value' => $this->options['element_label_colon'],
'#process' => array('ctools_dependent_process'),
'#dependency' => array(
'edit-options-custom-label' => array(1)
),
);
$form['element_label_type'] = array(
......@@ -374,7 +384,8 @@ class views_handler_field extends views_handler {
'#options' => $this->get_elements(FALSE),
'#type' => 'select',
'#default_value' => $this->options['element_label_type'],
'#description' => t('What HTML Element type to use to wrap the label.'),
'#description' => t('What HTML element type to use to wrap the label.'),
'#fieldset' => 'style_settings',
);
$form['element_label_class'] = array(
......@@ -382,13 +393,7 @@ class views_handler_field extends views_handler {
'#description' => t('The class to provide on the label wrapper element.'),
'#type' => 'textfield',
'#default_value' => $this->options['element_label_class'],
);
$form['element_label_colon'] = array(
'#type' => 'checkbox',
'#title' => t('Place a colon after the label'),
'#default_value' => $this->options['element_label_colon'],
'#description' => t('If the label is to be inline with the value, place a colon between them. Not valid for styles such as table where the label is not placed with the value.'),
'#fieldset' => 'style_settings',
);
$form['element_wrapper_type'] = array(
......@@ -397,6 +402,7 @@ class views_handler_field extends views_handler {
'#type' => 'select',
'#default_value' => $this->options['element_wrapper_type'],
'#description' => t('What HTML Element type to use to wrap the field (and the label). This is not supported by some styles such as tables.'),
'#fieldset' => 'style_settings',
);
$form['element_wrapper_class'] = array(
......@@ -404,6 +410,7 @@ class views_handler_field extends views_handler {
'#description' => t('The class to provide on the wrapper element.'),
'#type' => 'textfield',
'#default_value' => $this->options['element_wrapper_class'],
'#fieldset' => 'style_settings',
);
$form['element_default_classes'] = array(
......@@ -411,15 +418,29 @@ class views_handler_field extends views_handler {
'#title' => t('Add default classes'),
'#default_value' => $this->options['element_default_classes'],
'#description' => t('Use default Views classes to identify the field, field label and field content.'),
'#fieldset' => 'style_settings',
);
$form['exclude'] = array(
'#type' => 'checkbox',
'#title' => t('Exclude from display'),
'#default_value' => $this->options['exclude'],
'#description' => t('Check this box to not display this field, but still load it in the view. Use this option to not show a grouping field in each record, or when doing advanced theming, or when you want to use this field as a token in other fields.'),
'#fieldset' => 'style_settings',
);
$form['style_suffix'] = array(
'#value' => '</fieldset>',
$form['style_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Style settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['alter'] = array(
'#title' => t('Rewriting'),
'#title' => t('Rewrite results'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
if ($this->allow_advanced_render()) {
......@@ -653,36 +674,46 @@ If you would like to have the characters %5B and %5D please use the html entity
);
}
// Use prefix and suffix to fake a fieldset because we use #tree.
$form['empty_prefix'] = array(
'#value' => '<fieldset id="views-validator-options"><legend>' . t('Empty field behavior') . '</legend>',
$form['empty_field_behavior'] = array(
'#type' => 'fieldset',
'#title' => t('No results behavior'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['empty'] = array(
'#type' => 'textfield',
'#title' => t('Empty text'),
'#title' => t('No results text'),
'#default_value' => $this->options['empty'],
'#description' => t('If the field is empty, display this text instead.'),
'#description' => t('Provide text to display if this field returns no results.'),
'#fieldset' => 'empty_field_behavior',
);
$form['empty_zero'] = array(
'#type' => 'checkbox',
'#title' => t('Count the number 0 as empty'),
'#default_value' => $this->options['empty_zero'],
'#description' => t('If the field contains the number zero, display the empty text instead'),
'#description' => t('Enable to display the "no results text" if the field contains the number 0.'),
'#fieldset' => 'empty_field_behavior',
);
$form['hide_empty'] = array(
'#type' => 'checkbox',
'#title' => t('Hide if empty'),
'#default_value' => $this->options['hide_empty'],
'#description' => t('Do not display anything for this field if it is empty. Note that the field label may still be displayed. Check style or row style settings to hide labels for empty fields.'),
'#description' => t('Enable to hide this field if it is empty. Note that the field label may still be displayed. Check style or row style settings to hide labels for empty fields.'),
'#fieldset' => 'empty_field_behavior',
);
$form['empty_suffix'] = array(
'#value' => '</fieldset>',
// This form is long and messy enough that the "Administrative title" option
// belongs in a "more options" fieldset at the bottom of the form.
$form['more'] = array(
'#type' => 'fieldset',
'#title' => t('More'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['ui_name']['#fieldset'] = 'more';
}
/**
......
......@@ -39,7 +39,6 @@ class views_handler_field_boolean extends views_handler_field {
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
foreach ($this->formats as $key => $item) {
$options[$key] = implode('/', $item);
}
......@@ -56,6 +55,7 @@ class views_handler_field_boolean extends views_handler_field {
'#description' => t('If checked, true will be displayed as false.'),
'#default_value' => $this->options['not'],
);
parent::options_form($form, $form_state);
}
function render($values) {
......
......@@ -9,8 +9,6 @@ class views_handler_field_counter extends views_handler_field {
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['counter_start'] = array(
'#type' => 'textfield',
'#title' => t('Starting value'),
......@@ -19,6 +17,8 @@ class views_handler_field_counter extends views_handler_field {
//'#process' => array('ctools_dependent_process'),
'#size' => 2,
);
parent::options_form($form, $form_state);
}
function query() {
......
......@@ -16,8 +16,6 @@ class views_handler_field_date extends views_handler_field {
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['date_format'] = array(
'#type' => 'select',
'#title' => t('Date format'),
......@@ -41,6 +39,8 @@ class views_handler_field_date extends views_handler_field {
'#process' => array('ctools_dependent_process'),
'#dependency' => array('edit-options-date-format' => array('custom', 'raw time ago', 'time ago', 'raw time span', 'time span')),
);
parent::options_form($form, $form_state);
}
function render($values) {
......
......@@ -27,8 +27,6 @@ class views_handler_field_numeric extends views_handler_field {
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
if (!empty($this->definition['float'])) {
$form['set_precision'] = array(
'#type' => 'checkbox',
......@@ -94,6 +92,8 @@ class views_handler_field_numeric extends views_handler_field {
'#default_value' => $this->options['suffix'],
'#description' => t('Text to put after the number, such as currency symbol.'),
);
parent::options_form($form, $form_state);
}
function render($values) {
......
......@@ -22,7 +22,6 @@ class views_handler_field_prerender_list extends views_handler_field {
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['type'] = array(
'#type' => 'radios',
'#title' => t('Display type'),
......@@ -41,6 +40,7 @@ class views_handler_field_prerender_list extends views_handler_field {
'#process' => array('ctools_dependent_process'),
'#dependency' => array('radio:options[type]' => array('separator')),
);
parent::options_form($form, $form_state);
}
/**
......
......@@ -19,12 +19,12 @@ class views_handler_field_url extends views_handler_field {
* Provide link to the page being visited.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['display_as_link'] = array(
'#title' => t('Display as link'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['display_as_link']),
);
parent::options_form($form, $form_state);
}
function render($values) {
......
......@@ -1188,6 +1188,33 @@ function template_preprocess_views_ui_display_tab_column(&$variables) {
$variables['column'] = $element['#column'];
}
/**
* Move form elements into fieldsets for presentation purposes.
*
* Many views forms use #tree = TRUE to keep their values in a hierarchy for
* easier storage. Moving the form elements into fieldsets during form building
* would break up that hierarchy. Therefore, we wait until the pre_render stage,
* where any changes we make affect presentation only and aren't reflected in
* $form_state['values'].
*/
function views_ui_pre_render_add_fieldset_markup($form) {
$keys = element_children($form);
foreach ($keys as $key) {
$element = $form[$key];
// In our form builder functions, we added an arbitrary #fieldset property
// to any element that belongs in a fieldset. If this form element has that
// property, move it into its fieldset.
if (isset($element['#type']) && isset($element['#fieldset']) && isset($form[$element['#fieldset']])) {
$form[$element['#fieldset']][$key] = $element;
// Remove the original element this duplicates.
unset($form[$key]);
}
}
return $form;
}
/**
* Export a view for cut & paste.
*/
......
......@@ -215,10 +215,19 @@ class views_handler extends views_object {
*/
function options_validate(&$form, &$form_state) { }
/**
* Build the options form.
*/
function options_form(&$form, &$form_state) {
// Some form elements belong in a fieldset for presentation, but can't
// be moved into one because of the form_state['values'] hierarchy. Those
// elements can add a #fieldset => 'fieldset_name' property, and they'll
// be moved to their fieldset during pre_render.
$form['#pre_render'][] = 'views_ui_pre_render_add_fieldset_markup';
$form['ui_name'] = array(
'#type' => 'textfield',
'#title' => t('Administrative Title'),
'#title' => t('Administrative title'),
'#description' => t('This title will be displayed on the views edit page instead of the default one. This might be useful if you have the same item twice.'),
'#default_value' => $this->options['ui_name'],
);
......
......@@ -59,8 +59,6 @@ class views_handler_field_field extends views_handler_field {
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$field = field_info_field($this->definition['field_name']);
$formatters = _field_view_formatter_options($field['type']);
......@@ -100,6 +98,8 @@ class views_handler_field_field extends views_handler_field {
$settings_form = $function($field, $instance, '_dummy', $form, $form_state);
}
$form['settings'] = $settings_form;
parent::options_form($form, $form_state);
}
/**
......
......@@ -30,13 +30,14 @@ class views_handler_field_node extends views_handler_field {
* Provide link to node option
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['link_to_node'] = array(
'#title' => t('Link this field to its node'),
'#description' => t('This will override any other link you have set.'),
'#title' => t('Link this field to its original post'),
'#description' => t("Enable to override this field's links."),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_to_node']),
);
parent::options_form($form, $form_state);
}
/**
......
......@@ -17,11 +17,13 @@ class views_handler_field_node_type extends views_handler_field_node {
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['machine_name'] = array(
'#title' => t('Output machine name'),
'#description' => t('Display field as the node type machine name.'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['machine_name']),
'#fieldset' => 'more',
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment