diff --git a/handlers/views_handler_field.inc b/handlers/views_handler_field.inc index f514d94dbc74780b5bb4db7072e6cad538b5d85c..7483fd56bcd10ecd38436c755f034693fcd06c1e 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' => '
' . t('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.'), - ); - $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' => '
', + $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' => '
' . t('Empty field behavior') . '', + $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' => '
', + // 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 ad2ee71045e236225cb63704dd7a0b70f03be85c..27bf565ed1fbf5c7a1f17f99d18410060180b6da 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 4bf4c2ad149db48c2d08e6c7ebe325088977d7e7..86dc80d4026d69de8582e3b7d3fe1165067a87d0 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 c69289a1e999f39bf62199a6a83ef1f7630c5f86..2d69555aaa63f70d92453949b1905fabca57c754 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 a9ccb61f7f6e3629afe5db7ac39cbd8ef3de4737..b4599ffc1643d07fa02dd567f1dd4ef5ce1b9f89 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 a8869ad51b2922460132096935fea783b03aec91..4c579bb5dca1b1d432e0fbb0f882ef009ba1ca28 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 dc3cd363cac8d6f4df672d4689b2130d0e9751a5..ef8f1545f8a7aa976e75789c4b35a55d51f14fbd 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 c0f3bad6b17f82a2b857c760fcebd2f55ceb416a..1155627fee8af9ed847e8b0eb6262a48da3fe839 100644 --- a/includes/admin.inc +++ b/includes/admin.inc @@ -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. */ diff --git a/includes/handlers.inc b/includes/handlers.inc index fe8acea17e9d7b7ddc73e772901329a9f3bdf3ce..804f5b74b1d7532a892978627fa74d4eaeaf633a 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 c13e09cddb7bd1e91e1b18d0ab6723809d889d64..b41d510d2071ab1cf06c78f651e566199b9aafc6 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 b405b0d8c42a21ad21efa1ae5083ee0311105a7e..994713de67f987da97eb8774a7031392081fc026 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 038fa004a84b58cfbcf67899db8ad8351e9fec91..2cd28dda91742e72734539a9a2766f8027f25b7a 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', ); }