summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKatherine Senzee2011-01-10 18:43:20 (GMT)
committerKatherine Senzee2011-01-10 18:43:20 (GMT)
commit25090dbed975782eebd22905090889038eae8df3 (patch)
tree3f30dca54da7e4557cc94075cbffbcc23d881879
parentdd50052cb700c0626a807bfca65b82f13e7ac1b8 (diff)
Move field options form items into fieldsets for better UX.
-rw-r--r--handlers/views_handler_field.inc99
-rw-r--r--handlers/views_handler_field_boolean.inc2
-rw-r--r--handlers/views_handler_field_counter.inc4
-rw-r--r--handlers/views_handler_field_date.inc4
-rw-r--r--handlers/views_handler_field_numeric.inc4
-rw-r--r--handlers/views_handler_field_prerender_list.inc2
-rw-r--r--handlers/views_handler_field_url.inc2
-rw-r--r--includes/admin.inc27
-rw-r--r--includes/handlers.inc11
-rw-r--r--modules/field/views_handler_field_field.inc4
-rw-r--r--modules/node/views_handler_field_node.inc7
-rw-r--r--modules/node/views_handler_field_node_type.inc2
12 files changed, 119 insertions, 49 deletions
diff --git a/handlers/views_handler_field.inc b/handlers/views_handler_field.inc
index f514d94..7483fd5 100644
--- a/handlers/views_handler_field.inc
+++ b/handlers/views_handler_field.inc
@@ -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';
}
/**
diff --git a/handlers/views_handler_field_boolean.inc b/handlers/views_handler_field_boolean.inc
index ad2ee71..27bf565 100644
--- a/handlers/views_handler_field_boolean.inc
+++ b/handlers/views_handler_field_boolean.inc
@@ -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) {
diff --git a/handlers/views_handler_field_counter.inc b/handlers/views_handler_field_counter.inc
index 4bf4c2a..86dc80d 100644
--- a/handlers/views_handler_field_counter.inc
+++ b/handlers/views_handler_field_counter.inc
@@ -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() {
diff --git a/handlers/views_handler_field_date.inc b/handlers/views_handler_field_date.inc
index c69289a..2d69555 100644
--- a/handlers/views_handler_field_date.inc
+++ b/handlers/views_handler_field_date.inc
@@ -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) {
diff --git a/handlers/views_handler_field_numeric.inc b/handlers/views_handler_field_numeric.inc
index a9ccb61..b4599ff 100644
--- a/handlers/views_handler_field_numeric.inc
+++ b/handlers/views_handler_field_numeric.inc
@@ -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) {
diff --git a/handlers/views_handler_field_prerender_list.inc b/handlers/views_handler_field_prerender_list.inc
index a8869ad..4c579bb 100644
--- a/handlers/views_handler_field_prerender_list.inc
+++ b/handlers/views_handler_field_prerender_list.inc
@@ -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);
}
/**
diff --git a/handlers/views_handler_field_url.inc b/handlers/views_handler_field_url.inc
index dc3cd36..ef8f154 100644
--- a/handlers/views_handler_field_url.inc
+++ b/handlers/views_handler_field_url.inc
@@ -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) {
diff --git a/includes/admin.inc b/includes/admin.inc
index c0f3bad..1155627 100644
--- a/includes/admin.inc
+++ b/includes/admin.inc
@@ -1189,6 +1189,33 @@ function template_preprocess_views_ui_display_tab_column(&$variables) {
}
/**
+ * 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.
*/
function views_ui_export_page($form, &$form_state, $view) {
diff --git a/includes/handlers.inc b/includes/handlers.inc
index fe8acea..804f5b7 100644
--- a/includes/handlers.inc
+++ b/includes/handlers.inc
@@ -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'],
);
diff --git a/modules/field/views_handler_field_field.inc b/modules/field/views_handler_field_field.inc
index c13e09c..b41d510 100644
--- a/modules/field/views_handler_field_field.inc
+++ b/modules/field/views_handler_field_field.inc
@@ -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);
}
/**
diff --git a/modules/node/views_handler_field_node.inc b/modules/node/views_handler_field_node.inc
index b405b0d..994713d 100644
--- a/modules/node/views_handler_field_node.inc
+++ b/modules/node/views_handler_field_node.inc
@@ -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);
}
/**
diff --git a/modules/node/views_handler_field_node_type.inc b/modules/node/views_handler_field_node_type.inc
index 038fa00..2cd28dd 100644
--- a/modules/node/views_handler_field_node_type.inc
+++ b/modules/node/views_handler_field_node_type.inc
@@ -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',
);
}