diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php index 763622f..c1041dd 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php @@ -280,8 +280,8 @@ public function buildOptionsForm(&$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 preRender. - $form['#pre_render'][] = 'views_ui_pre_render_add_fieldset_markup'; + // be moved to their fieldset during pre_render. + $form['#pre_render'][] = array($this, 'preRenderAddFieldsetMarkup'); parent::buildOptionsForm($form, $form_state); diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php index 3258afb..a31d291 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php @@ -216,8 +216,8 @@ public function buildOptionsForm(&$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 preRender. - $form['#pre_render'][] = 'views_ui_pre_render_add_fieldset_markup'; + // be moved to their fieldset during pre_render. + $form['#pre_render'][] = array($this, 'preRenderAddFieldsetMarkup'); } /** @@ -364,4 +364,63 @@ public function globalTokenForm(&$form, &$form_state) { ); } + /** + * Moves 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']. + * + * @param array $form + * The form build array to alter. + * + * @return array + * The form build array. + */ + public function preRenderAddFieldsetMarkup(array $form) { + foreach (element_children($form) 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['#fieldset']) && isset($form[$element['#fieldset']])) { + $form[$element['#fieldset']][$key] = $element; + // Remove the original element this duplicates. + unset($form[$key]); + } + } + + return $form; + } + + /** + * Flattens the structure of form elements. + * + * If a form element has #flatten = TRUE, then all of it's children get moved + * to the same level as the element itself. So $form['to_be_flattened'][$key] + * becomes $form[$key], and $form['to_be_flattened'] gets unset. + * + * @param array $form + * The form build array to alter. + * + * @return array + * The form build array. + */ + public function preRenderFlattenData($form) { + foreach (element_children($form) as $key) { + $element = $form[$key]; + if (!empty($element['#flatten'])) { + foreach (element_children($element) as $child_key) { + $form[$child_key] = $form[$key][$child_key]; + } + // All done, remove the now-empty parent. + unset($form[$key]); + } + } + + return $form; + } + } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php index 0b0f992..0e59061 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php @@ -165,7 +165,7 @@ public function buildOptionsForm(&$form, &$form_state) { $argument_text = $this->view->display_handler->getArgumentText(); - $form['#pre_render'][] = 'views_ui_pre_render_move_argument_options'; + $form['#pre_render'][] = array($this, 'preRenderMoveArgumentOptions'); $form['description'] = array( '#markup' => $argument_text['description'], @@ -1119,6 +1119,32 @@ public static function processContainerRadios($element) { return $element; } + /** + * Moves argument options into their place. + * + * When configuring the default argument behavior, almost each of the radio + * buttons has its own fieldset shown bellow it when the radio button is + * clicked. That fieldset is created through a custom form process callback. + * Each element that has #argument_option defined and pointing to a default + * behavior gets moved to the appropriate fieldset. + * So if #argument_option is specified as 'default', the element is moved + * to the 'default_options' fieldset. + */ + public function preRenderMoveArgumentOptions($form) { + foreach (element_children($form) as $key) { + $element = $form[$key]; + if (!empty($element['#argument_option'])) { + $container_name = $element['#argument_option'] . '_options'; + if (isset($form['no_argument']['default_action'][$container_name])) { + $form['no_argument']['default_action'][$container_name][$key] = $element; + } + // Remove the original element this duplicates. + unset($form[$key]); + } + } + return $form; + } + } /** diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php index ba2adde..97c4f90 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php @@ -497,7 +497,7 @@ public function buildExposeForm(&$form, &$form_state) { // prior to rendering. That's why the preRender for it needs to run first, // so that when the next preRender (the one for fieldsets) runs, it gets // the flattened data. - array_unshift($form['#pre_render'], 'views_ui_pre_render_flatten_data'); + array_unshift($form['#pre_render'], array($this, 'preRenderFlattenData')); $form['expose']['#flatten'] = TRUE; if (empty($this->always_required)) { @@ -832,7 +832,7 @@ protected function buildExposedFiltersGroupForm(&$form, &$form_state) { // prior to rendering. That's why the preRender for it needs to run first, // so that when the next preRender (the one for fieldsets) runs, it gets // the flattened data. - array_unshift($form['#pre_render'], 'views_ui_pre_render_flatten_data'); + array_unshift($form['#pre_render'], array($this, 'preRenderFlattenData')); $form['group_info']['#flatten'] = TRUE; if (!empty($this->options['group_info']['identifier'])) { diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/sort/SortPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/sort/SortPluginBase.php index d9b6326..c83426b 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/sort/SortPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/sort/SortPluginBase.php @@ -192,7 +192,7 @@ public function buildExposeForm(&$form, &$form_state) { // prior to rendering. That's why the preRender for it needs to run first, // so that when the next preRender (the one for fieldsets) runs, it gets // the flattened data. - array_unshift($form['#pre_render'], 'views_ui_pre_render_flatten_data'); + array_unshift($form['#pre_render'], array($this, 'preRenderFlattenData')); $form['expose']['#flatten'] = TRUE; $form['expose']['label'] = array( diff --git a/core/modules/views_ui/admin.inc b/core/modules/views_ui/admin.inc index 8631f25..70d1c42 100644 --- a/core/modules/views_ui/admin.inc +++ b/core/modules/views_ui/admin.inc @@ -255,89 +255,6 @@ function views_ui_taxonomy_autocomplete_validate($element, &$form_state) { } /** - * Move form elements into details 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 preRender 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) { - foreach (element_children($form) 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['#fieldset']) && isset($form[$element['#fieldset']])) { - $form[$element['#fieldset']][$key] = $element; - // Remove the original element this duplicates. - unset($form[$key]); - } - } - - // Hide the fieldsets if there is nothing in there. - if (isset($form['fieldsets']['#value'])) { - foreach ($form['fieldsets']['#value'] as $fieldset) { - if (!element_children($form[$fieldset])) { - $form[$fieldset]['#access'] = FALSE; - } - } - } - - return $form; -} - -/** - * Flattens the structure of an element containing the #flatten property. - * - * If a form element has #flatten = TRUE, then all of it's children - * get moved to the same level as the element itself. - * So $form['to_be_flattened'][$key] becomes $form[$key], and - * $form['to_be_flattened'] gets unset. - */ -function views_ui_pre_render_flatten_data($form) { - foreach (element_children($form) as $key) { - $element = $form[$key]; - if (!empty($element['#flatten'])) { - foreach (element_children($element) as $child_key) { - $form[$child_key] = $form[$key][$child_key]; - } - // All done, remove the now-empty parent. - unset($form[$key]); - } - } - - return $form; -} - -/** - * Moves argument options into their place. - * - * When configuring the default argument behavior, almost each of the radio - * buttons has its own fieldset shown bellow it when the radio button is - * clicked. That fieldset is created through a custom form process callback. - * Each element that has #argument_option defined and pointing to a default - * behavior gets moved to the appropriate fieldset. - * So if #argument_option is specified as 'default', the element is moved - * to the 'default_options' fieldset. - */ -function views_ui_pre_render_move_argument_options($form) { - foreach (element_children($form) as $key) { - $element = $form[$key]; - if (!empty($element['#argument_option'])) { - $container_name = $element['#argument_option'] . '_options'; - if (isset($form['no_argument']['default_action'][$container_name])) { - $form['no_argument']['default_action'][$container_name][$key] = $element; - } - // Remove the original element this duplicates. - unset($form[$key]); - } - } - return $form; -} - -/** * Add a