From 4406aa9ff0fa8aa393b8269e92a60e33f1916417 Mon Sep 17 00:00:00 2001 From: Tim Plunkett <git@plnktt.com> Date: Sun, 30 Sep 2012 17:53:21 -0400 Subject: [PATCH] Issue #1792860 by tim.plunkett, dawehner: Move Views UI into its own module. --- .../Plugin/views/wizard/WizardPluginBase.php | 6 +- lib/Drupal/views/ViewStorage.php | 3 +- theme/theme.inc | 8 - views.module | 2 +- {includes => views_ui}/admin.inc | 504 +---------------- {css => views_ui/css}/views-admin-rtl.css | 0 .../css}/views-admin.bartik-rtl.css | 0 {css => views_ui/css}/views-admin.bartik.css | 0 .../css}/views-admin.contextual.css | 0 {css => views_ui/css}/views-admin.css | 0 .../css}/views-admin.ctools-rtl.css | 0 {css => views_ui/css}/views-admin.ctools.css | 0 .../css}/views-admin.seven-rtl.css | 0 {css => views_ui/css}/views-admin.seven.css | 0 .../css}/views-admin.theme-rtl.css | 0 {css => views_ui/css}/views-admin.theme.css | 0 {images => views_ui/images}/arrow-active.png | 0 {images => views_ui/images}/close.png | 0 .../images}/expanded-options.png | 0 {images => views_ui/images}/loading-small.gif | 0 {images => views_ui/images}/loading.gif | 0 {images => views_ui/images}/overridden.gif | 0 {images => views_ui/images}/sprites.png | 0 {images => views_ui/images}/status-active.gif | 0 {js => views_ui/js}/views-admin.js | 0 .../Drupal/views_ui}/ViewListController.php | 4 +- .../lib/Drupal/views_ui}/ViewUI.php | 58 +- views_ui/theme/theme.inc | 513 ++++++++++++++++++ .../views-ui-display-tab-bucket.tpl.php | 0 .../views-ui-display-tab-setting.tpl.php | 0 .../theme}/views-ui-edit-item.tpl.php | 0 .../theme}/views-ui-edit-view.tpl.php | 0 views_ui.info => views_ui/views_ui.info | 0 views_ui.module => views_ui/views_ui.module | 116 +--- 34 files changed, 614 insertions(+), 600 deletions(-) rename {includes => views_ui}/admin.inc (84%) rename {css => views_ui/css}/views-admin-rtl.css (100%) rename {css => views_ui/css}/views-admin.bartik-rtl.css (100%) rename {css => views_ui/css}/views-admin.bartik.css (100%) rename {css => views_ui/css}/views-admin.contextual.css (100%) rename {css => views_ui/css}/views-admin.css (100%) rename {css => views_ui/css}/views-admin.ctools-rtl.css (100%) rename {css => views_ui/css}/views-admin.ctools.css (100%) rename {css => views_ui/css}/views-admin.seven-rtl.css (100%) rename {css => views_ui/css}/views-admin.seven.css (100%) rename {css => views_ui/css}/views-admin.theme-rtl.css (100%) rename {css => views_ui/css}/views-admin.theme.css (100%) rename {images => views_ui/images}/arrow-active.png (100%) rename {images => views_ui/images}/close.png (100%) rename {images => views_ui/images}/expanded-options.png (100%) rename {images => views_ui/images}/loading-small.gif (100%) rename {images => views_ui/images}/loading.gif (100%) rename {images => views_ui/images}/overridden.gif (100%) rename {images => views_ui/images}/sprites.png (100%) rename {images => views_ui/images}/status-active.gif (100%) rename {js => views_ui/js}/views-admin.js (100%) rename {lib/Drupal/views => views_ui/lib/Drupal/views_ui}/ViewListController.php (98%) rename {lib/Drupal/views => views_ui/lib/Drupal/views_ui}/ViewUI.php (97%) create mode 100644 views_ui/theme/theme.inc rename {theme => views_ui/theme}/views-ui-display-tab-bucket.tpl.php (100%) rename {theme => views_ui/theme}/views-ui-display-tab-setting.tpl.php (100%) rename {theme => views_ui/theme}/views-ui-edit-item.tpl.php (100%) rename {theme => views_ui/theme}/views-ui-edit-view.tpl.php (100%) rename views_ui.info => views_ui/views_ui.info (100%) rename views_ui.module => views_ui/views_ui.module (87%) diff --git a/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php b/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php index 990a40cba1a0..c85bc80ec1cd 100644 --- a/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php +++ b/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php @@ -8,7 +8,7 @@ namespace Drupal\views\Plugin\views\wizard; use Drupal\views\ViewStorage; -use Drupal\views\ViewUI; +use Drupal\views_ui\ViewUI; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\PluginBase; use Drupal\views\Plugin\views\wizard\WizardInterface; @@ -1029,7 +1029,7 @@ protected function set_override_options(array $options, DisplayPluginBase $displ * @param bool $unset * Should the view be removed from the list of validated views. * - * @return Drupal\views\ViewUI $view + * @return Drupal\views_ui\ViewUI $view * The validated view object. */ protected function retrieve_validated_view(array $form, array &$form_state, $unset = TRUE) { @@ -1050,7 +1050,7 @@ protected function retrieve_validated_view(array $form, array &$form_state, $uns * The full wizard form array. * @param array $form_state * The current state of the wizard form. - * @param Drupal\views\ViewUI $view + * @param Drupal\views_ui\ViewUI $view * The validated view object. */ protected function set_validated_view(array $form, array &$form_state, ViewUI $view) { diff --git a/lib/Drupal/views/ViewStorage.php b/lib/Drupal/views/ViewStorage.php index 439880c2aec5..7f81edae992c 100644 --- a/lib/Drupal/views/ViewStorage.php +++ b/lib/Drupal/views/ViewStorage.php @@ -8,6 +8,7 @@ namespace Drupal\views; use Drupal\Core\Config\Entity\ConfigEntityBase; +use Drupal\views_ui\ViewUI; /** * Defines a ViewStorage configuration entity class. @@ -130,7 +131,7 @@ public function setExecutable(ViewExecutable $executable) { * @param bool $reset * Get a new Drupal\views\ViewExecutable instance. * @param bool $ui - * If this should return Drupal\views\ViewUI instead. + * If this should return Drupal\views_ui\ViewUI instead. * * @return Drupal\views\ViewExecutable * The executable version of this view. diff --git a/theme/theme.inc b/theme/theme.inc index 9a4a227b0a8c..d9aacecfcda3 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -1082,14 +1082,6 @@ function theme_views_mini_pager($vars) { } } -/** - * Generic <div> container function. - */ -function theme_views_container($variables) { - $element = $variables['element']; - return '<div' . new Attribute($element['#attributes']) . '>' . $element['#children'] . '</div>'; -} - /** * @defgroup views_templates Views template files * @{ diff --git a/views.module b/views.module index c5e6056cfa92..5af807fb25c9 100644 --- a/views.module +++ b/views.module @@ -88,7 +88,7 @@ function views_entity_info() { 'label' => t('View'), 'entity class' => 'Drupal\views\ViewStorage', 'controller class' => 'Drupal\views\ViewStorageController', - 'list controller class' => 'Drupal\views\ViewListController', + 'list controller class' => 'Drupal\views_ui\ViewListController', 'list path' => 'admin/structure/views', 'form controller class' => array( 'default' => 'Drupal\node\NodeFormController', diff --git a/includes/admin.inc b/views_ui/admin.inc similarity index 84% rename from includes/admin.inc rename to views_ui/admin.inc index 82d77e392e00..57059063af8c 100644 --- a/includes/admin.inc +++ b/views_ui/admin.inc @@ -6,19 +6,17 @@ */ use Drupal\Core\Database\Database; -use Drupal\views\ViewUI; +use Drupal\views_ui\ViewUI; use Drupal\views\Analyzer; use Drupal\views\Plugin\views\wizard\WizardException; /** * Returns the results of the live preview. */ -function views_ui_preview(ViewUI $view, $display_id, $args = array()) { - // When this function is invoked as a page callback, each Views argument is - // passed separately. - if (!is_array($args)) { - $args = array_slice(func_get_args(), 2); - } +function views_ui_preview(ViewUI $view, $display_id) { + // Pass along any other arguments. + $args = func_get_args(); + unset($args[0], $args[1]); return $view->renderPreview($display_id, $args); } @@ -28,7 +26,7 @@ function views_ui_preview(ViewUI $view, $display_id, $args = array()) { function views_ui_add_page() { drupal_set_title(t('Add new view')); $form_state['build_info']['args'] = array(); - $form_state['build_info']['callback'] = array('Drupal\views\ViewUI', 'addForm'); + $form_state['build_info']['callback'] = array('Drupal\views_ui\ViewUI', 'buildAddForm'); return drupal_build_form('views_ui_add_form', $form_state); } @@ -428,26 +426,6 @@ function views_ui_taxonomy_autocomplete_validate($element, &$form_state) { form_set_value($element, $value, $form_state); } -/** - * Implements hook_preprocess_HOOK() for theme_views_ui_view_info(). - */ -function template_preprocess_views_ui_view_info(&$variables) { - $variables['title'] = $variables['view']->getHumanName(); - - $displays = $variables['view']->getDisplaysList(); - $variables['displays'] = empty($displays) ? t('None') : format_plural(count($displays), 'Display', 'Displays') . ': ' . '<em>' . implode(', ', $displays) . '</em>'; -} - -/** - * Returns basic administrative information about a view. - */ -function theme_views_ui_view_info($variables) { - $output = ''; - $output .= '<div class="views-ui-view-title">' . $variables['title'] . "</div>\n"; - $output .= '<div class="views-ui-view-displays">' . $variables['displays'] . "</div>\n"; - return $output; -} - /** * Page to delete a view. */ @@ -485,7 +463,7 @@ function views_ui_edit_page(ViewUI $view, $display_id = NULL) { if (!in_array($display_id, array(MENU_ACCESS_DENIED, MENU_NOT_FOUND))) { $build = array(); $form_state['build_info']['args'] = array($display_id); - $form_state['build_info']['callback'] = array($view, 'editForm'); + $form_state['build_info']['callback'] = array($view, 'buildEditForm'); $build['edit_form'] = drupal_build_form('views_ui_edit_form', $form_state); $build['preview'] = views_ui_build_preview($view, $display_id, FALSE); } @@ -511,59 +489,16 @@ function views_ui_build_preview(ViewUI $view, $display_id, $render = TRUE) { $args = explode('/', $form_state['values']['view_args']); } - $build['preview'] = array( - '#theme_wrappers' => array('container'), - '#attributes' => array('id' => 'views-live-preview'), - '#markup' => $render ? views_ui_preview($view->cloneView(FALSE, TRUE), $display_id, $args) : '', - ); - - return $build; -} - -function template_preprocess_views_ui_display_tab_setting(&$variables) { - static $zebra = 0; - $variables['zebra'] = ($zebra % 2 === 0 ? 'odd' : 'even'); - $zebra++; - - // Put the main link to the left side - array_unshift($variables['settings_links'], $variables['link']); - $variables['settings_links'] = implode('<span class="label"> | </span>', $variables['settings_links']); - - if (!empty($variables['defaulted'])) { - $variables['attributes']['class'][] = 'defaulted'; - } - if (!empty($variables['overridden'])) { - $variables['attributes']['class'][] = 'overridden'; - $variables['attributes_array']['title'][] = t('Overridden'); - } - - // Append a colon to the description, if requested. - if ($variables['description'] && $variables['description_separator']) { - $variables['description'] .= t(':'); - } -} - -function template_preprocess_views_ui_display_tab_bucket(&$variables) { - $element = $variables['element']; - - if (!empty($element['#name'])) { - $variables['attributes']['class'][] = drupal_html_class($element['#name']); - } - if (!empty($element['#overridden'])) { - $variables['attributes']['class'][] = 'overridden'; - $variables['attributes_array']['title'][] = t('Overridden'); + if ($render) { + $clone = $view->cloneView(); + $build['preview'] = array( + '#theme_wrappers' => array('container'), + '#attributes' => array('id' => 'views-live-preview'), + '#markup' => $clone->renderPreview($display_id, $args), + ); } - $variables['content'] = $element['#children']; - $variables['title'] = $element['#title']; - $variables['actions'] = !empty($element['#actions']) ? $element['#actions'] : ''; -} - -function template_preprocess_views_ui_display_tab_column(&$variables) { - $element = $variables['element']; - - $variables['content'] = $element['#children']; - $variables['column'] = $element['#column']; + return $build; } /** @@ -852,34 +787,6 @@ function views_ui_ajax_forms($key = NULL) { return $forms; } -/** - * Build up a $form_state object suitable for use with drupal_build_form - * based on known information about a form. - */ -function views_ui_build_form_state($js, $key, ViewUI $view, $display_id, $args) { - $form = views_ui_ajax_forms($key); - // Build up form state - $form_state = array( - 'form_key' => $key, - 'form_id' => $form['form_id'], - 'view' => &$view, - 'ajax' => $js, - 'display_id' => $display_id, - 'no_redirect' => TRUE, - ); - // If an method was specified, use that for the callback. - if (isset($form['callback'])) { - $form_state['build_info']['args'] = array(); - $form_state['build_info']['callback'] = array($view, $form['callback']); - } - - foreach ($form['args'] as $id) { - $form_state[$id] = (!empty($args)) ? array_shift($args) : NULL; - } - - return $form_state; -} - /** * Create the URL for one of our standard AJAX forms based upon known * information about the form. @@ -912,7 +819,7 @@ function views_ui_ajax_form($js, $key, ViewUI $view, $display_id = '') { // Remove the known args array_splice($args, 0, 4); - $form_state = views_ui_build_form_state($js, $key, $view, $display_id, $args); + $form_state = $view->buildFormState($js, $key, $display_id, $args); // check to see if this is the top form of the stack. If it is, pop // it off; if it isn't, the user clicked somewhere else and the stack is // now irrelevant. @@ -952,7 +859,7 @@ function views_ui_ajax_form($js, $key, ViewUI $view, $display_id = '') { $stack = $view->stack; $top = array_shift($stack); $top[0] = $js; - $form_state = call_user_func_array('views_ui_build_form_state', $top); + $form_state = call_user_func_array(array($view, 'buildFormState'), $top); $form_state['input'] = array(); $form_state['url'] = url(views_ui_build_form_url($form_state)); if (!$js) { @@ -1014,64 +921,6 @@ function views_ui_analyze_view_form_submit($form, &$form_state) { $form_state['redirect'] = 'admin/structure/views/view/' . $form_state['view']->storage->name . '/edit'; } -/** - * Turn the reorder form into a proper table - */ -function theme_views_ui_reorder_displays_form($vars) { - $form = $vars['form']; - $rows = array(); - foreach (element_children($form) as $key) { - if (isset($form[$key]['#display'])) { - $display = &$form[$key]; - - $row = array(); - $row[] = drupal_render($display['title']); - $form[$key]['weight']['#attributes']['class'] = array('weight'); - $row[] = drupal_render($form[$key]['weight']); - if (isset($display['removed'])) { - $row[] = drupal_render($form[$key]['removed']) . - l('<span>' . t('Remove') . '</span>', - 'javascript:void()', - array( - 'attributes' => array( - 'id' => 'display-remove-link-' . $key, - 'class' => array('views-button-remove display-remove-link'), - 'alt' => t('Remove this display'), - 'title' => t('Remove this display')), - 'html' => TRUE)); - } - else { - $row[] = ''; - } - $class = array(); - $styles = array(); - if (isset($form[$key]['weight']['#type'])) { - $class[] = 'draggable'; - } - if (isset($form[$key]['deleted']['#value']) && $form[$key]['deleted']['#value']) { - $styles[] = 'display: none;'; - } - $rows[] = array('data' => $row, 'class' => $class, 'id' => 'display-row-' . $key, 'style' => $styles); - } - } - - $header = array(t('Display'), t('Weight'), t('Remove')); - $output = ''; - drupal_add_tabledrag('reorder-displays', 'order', 'sibling', 'weight'); - - $output = drupal_render($form['override']); - $output .= '<div class="scroll">'; - $output .= theme('table', - array('header' => $header, - 'rows' => $rows, - 'attributes' => array('id' => 'reorder-displays'), - )); - $output .= '</div>'; - $output .= drupal_render_children($form); - - return $output; -} - /** * Form builder to edit details of a view. */ @@ -1332,148 +1181,6 @@ function views_ui_rearrange_form($form, &$form_state) { return $form; } -/** - * Turn the rearrange form into a proper table - */ -function theme_views_ui_rearrange_form($variables) { - $form = $variables['form']; - - $rows = array(); - foreach (element_children($form['fields']) as $id) { - if (isset($form['fields'][$id]['name'])) { - $row = array(); - $row[] = drupal_render($form['fields'][$id]['name']); - $form['fields'][$id]['weight']['#attributes']['class'] = array('weight'); - $row[] = drupal_render($form['fields'][$id]['weight']); - $row[] = drupal_render($form['fields'][$id]['removed']) . l('<span>' . t('Remove') . '</span>', 'javascript:void()', array('attributes' => array('id' => 'views-remove-link-' . $id, 'class' => array('views-hidden', 'views-button-remove', 'views-remove-link'), 'alt' => t('Remove this item'), 'title' => t('Remove this item')), 'html' => TRUE)); - $rows[] = array('data' => $row, 'class' => array('draggable'), 'id' => 'views-row-' . $id); - } - } - if (empty($rows)) { - $rows[] = array(array('data' => t('No fields available.'), 'colspan' => '2')); - } - - $header = array('', t('Weight'), t('Remove')); - $output = drupal_render($form['override']); - $output .= '<div class="scroll">'; - $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'arrange'))); - $output .= '</div>'; - $output .= drupal_render_children($form); - drupal_add_tabledrag('arrange', 'order', 'sibling', 'weight'); - - return $output; -} - -/** - * Theme the expose filter form. - */ -function theme_views_ui_expose_filter_form($variables) { - $form = $variables['form']; - $more = drupal_render($form['more']); - - $output = drupal_render($form['form_description']); - $output .= drupal_render($form['expose_button']); - $output .= drupal_render($form['group_button']); - if (isset($form['required'])) { - $output .= drupal_render($form['required']); - } - $output .= drupal_render($form['label']); - $output .= drupal_render($form['description']); - - $output .= drupal_render($form['operator']); - $output .= drupal_render($form['value']); - - if (isset($form['use_operator'])) { - $output .= '<div class="views-left-40">'; - $output .= drupal_render($form['use_operator']); - $output .= '</div>'; - } - - // Only output the right column markup if there's a left column to begin with - if (!empty($form['operator']['#type'])) { - $output .= '<div class="views-right-60">'; - $output .= drupal_render_children($form); - $output .= '</div>'; - } - else { - $output .= drupal_render_children($form); - } - - $output .= $more; - - return $output; -} - -/** - * Theme the build group filter form. - */ -function theme_views_ui_build_group_filter_form($variables) { - $form = $variables['form']; - $more = drupal_render($form['more']); - - $output = drupal_render($form['form_description']); - $output .= drupal_render($form['expose_button']); - $output .= drupal_render($form['group_button']); - if (isset($form['required'])) { - $output .= drupal_render($form['required']); - } - - $output .= drupal_render($form['operator']); - $output .= drupal_render($form['value']); - - $output .= '<div class="views-left-40">'; - $output .= drupal_render($form['optional']); - $output .= drupal_render($form['remember']); - $output .= '</div>'; - - $output .= '<div class="views-right-60">'; - $output .= drupal_render($form['widget']); - $output .= drupal_render($form['label']); - $output .= drupal_render($form['description']); - $output .= '</div>'; - - $header = array( - t('Default'), - t('Weight'), - t('Label'), - t('Operator'), - t('Value'), - t('Operations'), - ); - - $form['default_group'] = form_process_radios($form['default_group']); - $form['default_group_multiple'] = form_process_checkboxes($form['default_group_multiple']); - $form['default_group']['All']['#title'] = ''; - - hide($form['default_group_multiple']['All']); - $rows[] = array( - drupal_render($form['default_group']['All']), - '', - array( - 'data' => config('views.settings')->get('ui.exposed_filter_any_label') == 'old_any' ? t('<Any>') : t('- Any -'), - 'colspan' => 4, - 'class' => array('class' => 'any-default-radios-row'), - ), - ); - - foreach (element_children($form['group_items']) as $group_id) { - $form['group_items'][$group_id]['value']['#title'] = ''; - $data = array( - 'default' => drupal_render($form['default_group'][$group_id]) . drupal_render($form['default_group_multiple'][$group_id]), - 'weight' => drupal_render($form['group_items'][$group_id]['weight']), - 'title' => drupal_render($form['group_items'][$group_id]['title']), - 'operator' => drupal_render($form['group_items'][$group_id]['operator']), - 'value' => drupal_render($form['group_items'][$group_id]['value']), - 'remove' => drupal_render($form['group_items'][$group_id]['remove']) . l('<span>' . t('Remove') . '</span>', 'javascript:void()', array('attributes' => array('id' => 'views-remove-link-' . $group_id, 'class' => array('views-hidden', 'views-button-remove', 'views-groups-remove-link', 'views-remove-link'), 'alt' => t('Remove this item'), 'title' => t('Remove this item')), 'html' => true)), - ); - $rows[] = array('data' => $data, 'id' => 'views-row-' . $group_id, 'class' => array('draggable')); - } - $table = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('class' => array('views-filter-groups'), 'id' => 'views-filter-groups'))) . drupal_render($form['add_group']); - drupal_add_tabledrag('views-filter-groups', 'order', 'sibling', 'weight'); - $render_form = drupal_render_children($form); - return $output . $render_form . $table . $more; -} - /** * Submit handler for rearranging form. */ @@ -1683,99 +1390,6 @@ function views_ui_rearrange_filter_form($form, &$form_state) { return $form; } -/** - * Turn the rearrange form into a proper table - */ -function theme_views_ui_rearrange_filter_form(&$vars) { - $form = $vars['form']; - $rows = $ungroupable_rows = array(); - // Enable grouping only if > 1 group. - $grouping = count(array_keys($form['#group_options'])) > 1; - - foreach ($form['#group_renders'] as $group_id => $contents) { - // Header row for the group. - if ($group_id !== 'ungroupable') { - // Set up tabledrag so that it changes the group dropdown when rows are - // dragged between groups. - drupal_add_tabledrag('views-rearrange-filters', 'match', 'sibling', 'views-group-select', 'views-group-select-' . $group_id); - - // Title row, spanning all columns. - $row = array(); - // Add a cell to the first row, containing the group operator. - $row[] = array('class' => array('group', 'group-operator', 'container-inline'), 'data' => drupal_render($form['filter_groups']['groups'][$group_id]), 'rowspan' => max(array(2, count($contents) + 1))); - // Title. - $row[] = array('class' => array('group', 'group-title'), 'data' => '<span>' . $form['#group_options'][$group_id] . '</span>', 'colspan' => 4); - $rows[] = array('class' => array('views-group-title'), 'data' => $row, 'id' => 'views-group-title-' . $group_id); - - // Row which will only appear if the group has nothing in it. - $row = array(); - $class = 'group-' . (count($contents) ? 'populated' : 'empty'); - $instructions = '<span>' . t('No filters have been added.') . '</span> <span class="js-only">' . t('Drag to add filters.') . '</span>'; - // When JavaScript is enabled, the button for removing the group (if it's - // present) should be hidden, since it will be replaced by a link on the - // client side. - if (!empty($form['remove_groups'][$group_id]['#type']) && $form['remove_groups'][$group_id]['#type'] == 'submit') { - $form['remove_groups'][$group_id]['#attributes']['class'][] = 'js-hide'; - } - $row[] = array('colspan' => 5, 'data' => $instructions . drupal_render($form['remove_groups'][$group_id])); - $rows[] = array('class' => array("group-message", "group-$group_id-message", $class), 'data' => $row, 'id' => 'views-group-' . $group_id); - } - - foreach ($contents as $id) { - if (isset($form['filters'][$id]['name'])) { - $row = array(); - $row[] = drupal_render($form['filters'][$id]['name']); - $form['filters'][$id]['weight']['#attributes']['class'] = array('weight'); - $row[] = drupal_render($form['filters'][$id]['weight']); - $form['filters'][$id]['group']['#attributes']['class'] = array('views-group-select views-group-select-' . $group_id); - $row[] = drupal_render($form['filters'][$id]['group']); - $form['filters'][$id]['removed']['#attributes']['class'][] = 'js-hide'; - $row[] = drupal_render($form['filters'][$id]['removed']) . l('<span>' . t('Remove') . '</span>', 'javascript:void()', array('attributes' => array('id' => 'views-remove-link-' . $id, 'class' => array('views-hidden', 'views-button-remove', 'views-groups-remove-link', 'views-remove-link'), 'alt' => t('Remove this item'), 'title' => t('Remove this item')), 'html' => TRUE)); - - $row = array('data' => $row, 'class' => array('draggable'), 'id' => 'views-row-' . $id); - if ($group_id !== 'ungroupable') { - $rows[] = $row; - } - else { - $ungroupable_rows[] = $row; - } - } - } - } - if (empty($rows)) { - $rows[] = array(array('data' => t('No fields available.'), 'colspan' => '2')); - } - - $output = drupal_render($form['override']); - $output .= '<div class="scroll">'; - if ($grouping) { - $output .= drupal_render($form['filter_groups']['operator']); - } - else { - $form['filter_groups']['groups'][0]['#title'] = t('Operator'); - $output .= drupal_render($form['filter_groups']['groups'][0]); - } - - if (!empty($ungroupable_rows)) { - drupal_add_tabledrag('views-rearrange-filters-ungroupable', 'order', 'sibling', 'weight'); - $header = array(t('Ungroupable filters'), t('Weight'), array('class' => array('views-hide-label'), 'data' => t('Group')), array('class' => array('views-hide-label'), 'data' => t('Remove'))); - $output .= theme('table', array('header' => $header, 'rows' => $ungroupable_rows, 'attributes' => array('id' => 'views-rearrange-filters-ungroupable', 'class' => array('arrange')))); - } - - // Set up tabledrag so that the weights are changed when rows are dragged. - drupal_add_tabledrag('views-rearrange-filters', 'order', 'sibling', 'weight'); - $output .= theme('table', array('rows' => $rows, 'attributes' => array('id' => 'views-rearrange-filters', 'class' => array('arrange')))); - $output .= '</div>'; - - // When JavaScript is enabled, the button for adding a new group should be - // hidden, since it will be replaced by a link on the client side. - $form['buttons']['add_group']['#attributes']['class'][] = 'js-hide'; - - // Render the rest of the form and return. - $output .= drupal_render_children($form); - return $output; -} - /** * Submit handler for rearranging form */ @@ -2008,7 +1622,7 @@ function views_ui_add_item_form($form, &$form_state) { '#type' => 'item', '#markup' => '<div class="views-selected-options"></div>', '#title' => t('Selected') . ':', - '#theme_wrappers' => array('form_element', 'views_container'), + '#theme_wrappers' => array('form_element', 'views_ui_container'), '#attributes' => array('class' => array('container-inline', 'views-add-form-selected')), ); $view->getStandardButtons($form, $form_state, 'views_ui_add_item_form', t('Add and configure @types', array('@types' => $ltitle))); @@ -3039,77 +2653,6 @@ function views_fetch_fields($base, $type, $grouping = FALSE) { return array(); } -/** - * Theme the form for the table style plugin - */ -function theme_views_ui_style_plugin_table($variables) { - $form = $variables['form']; - - $output = drupal_render($form['description_markup']); - - $header = array( - t('Field'), - t('Column'), - t('Align'), - t('Separator'), - array( - 'data' => t('Sortable'), - 'align' => 'center', - ), - array( - 'data' => t('Default order'), - 'align' => 'center', - ), - array( - 'data' => t('Default sort'), - 'align' => 'center', - ), - array( - 'data' => t('Hide empty column'), - 'align' => 'center', - ), - ); - $rows = array(); - foreach (element_children($form['columns']) as $id) { - $row = array(); - $row[] = drupal_render($form['info'][$id]['name']); - $row[] = drupal_render($form['columns'][$id]); - $row[] = drupal_render($form['info'][$id]['align']); - $row[] = drupal_render($form['info'][$id]['separator']); - if (!empty($form['info'][$id]['sortable'])) { - $row[] = array( - 'data' => drupal_render($form['info'][$id]['sortable']), - 'align' => 'center', - ); - $row[] = array( - 'data' => drupal_render($form['info'][$id]['default_sort_order']), - 'align' => 'center', - ); - $row[] = array( - 'data' => drupal_render($form['default'][$id]), - 'align' => 'center', - ); - } - else { - $row[] = ''; - $row[] = ''; - $row[] = ''; - } - $row[] = array( - 'data' => drupal_render($form['info'][$id]['empty_column']), - 'align' => 'center', - ); - $rows[] = $row; - } - - // Add the special 'None' row. - $rows[] = array(t('None'), '', '', '', '', '', array('align' => 'center', 'data' => drupal_render($form['default'][-1])), ''); - - $output .= theme('table', array('header' => $header, 'rows' => $rows)); - $output .= drupal_render_children($form); - return $output; -} - /** * #process callback for a button; determines if a button is the form's triggering element. * @@ -3133,17 +2676,6 @@ function views_ui_form_button_was_clicked($element, &$form_state) { return $element; } -/** - * #process callback for a button; makes implicit form submissions trigger as this button. - * - * @see Drupal.behaviors.viewsImplicitFormSubmission - */ -function views_ui_default_button($element, &$form_state, $form) { - $setting['viewsImplicitFormSubmission'][$form['#id']]['defaultButton'] = $element['#id']; - $element['#attached']['js'][] = array('type' => 'setting', 'data' => $setting); - return $element; -} - /** * List all instances of fields on any views. * diff --git a/css/views-admin-rtl.css b/views_ui/css/views-admin-rtl.css similarity index 100% rename from css/views-admin-rtl.css rename to views_ui/css/views-admin-rtl.css diff --git a/css/views-admin.bartik-rtl.css b/views_ui/css/views-admin.bartik-rtl.css similarity index 100% rename from css/views-admin.bartik-rtl.css rename to views_ui/css/views-admin.bartik-rtl.css diff --git a/css/views-admin.bartik.css b/views_ui/css/views-admin.bartik.css similarity index 100% rename from css/views-admin.bartik.css rename to views_ui/css/views-admin.bartik.css diff --git a/css/views-admin.contextual.css b/views_ui/css/views-admin.contextual.css similarity index 100% rename from css/views-admin.contextual.css rename to views_ui/css/views-admin.contextual.css diff --git a/css/views-admin.css b/views_ui/css/views-admin.css similarity index 100% rename from css/views-admin.css rename to views_ui/css/views-admin.css diff --git a/css/views-admin.ctools-rtl.css b/views_ui/css/views-admin.ctools-rtl.css similarity index 100% rename from css/views-admin.ctools-rtl.css rename to views_ui/css/views-admin.ctools-rtl.css diff --git a/css/views-admin.ctools.css b/views_ui/css/views-admin.ctools.css similarity index 100% rename from css/views-admin.ctools.css rename to views_ui/css/views-admin.ctools.css diff --git a/css/views-admin.seven-rtl.css b/views_ui/css/views-admin.seven-rtl.css similarity index 100% rename from css/views-admin.seven-rtl.css rename to views_ui/css/views-admin.seven-rtl.css diff --git a/css/views-admin.seven.css b/views_ui/css/views-admin.seven.css similarity index 100% rename from css/views-admin.seven.css rename to views_ui/css/views-admin.seven.css diff --git a/css/views-admin.theme-rtl.css b/views_ui/css/views-admin.theme-rtl.css similarity index 100% rename from css/views-admin.theme-rtl.css rename to views_ui/css/views-admin.theme-rtl.css diff --git a/css/views-admin.theme.css b/views_ui/css/views-admin.theme.css similarity index 100% rename from css/views-admin.theme.css rename to views_ui/css/views-admin.theme.css diff --git a/images/arrow-active.png b/views_ui/images/arrow-active.png similarity index 100% rename from images/arrow-active.png rename to views_ui/images/arrow-active.png diff --git a/images/close.png b/views_ui/images/close.png similarity index 100% rename from images/close.png rename to views_ui/images/close.png diff --git a/images/expanded-options.png b/views_ui/images/expanded-options.png similarity index 100% rename from images/expanded-options.png rename to views_ui/images/expanded-options.png diff --git a/images/loading-small.gif b/views_ui/images/loading-small.gif similarity index 100% rename from images/loading-small.gif rename to views_ui/images/loading-small.gif diff --git a/images/loading.gif b/views_ui/images/loading.gif similarity index 100% rename from images/loading.gif rename to views_ui/images/loading.gif diff --git a/images/overridden.gif b/views_ui/images/overridden.gif similarity index 100% rename from images/overridden.gif rename to views_ui/images/overridden.gif diff --git a/images/sprites.png b/views_ui/images/sprites.png similarity index 100% rename from images/sprites.png rename to views_ui/images/sprites.png diff --git a/images/status-active.gif b/views_ui/images/status-active.gif similarity index 100% rename from images/status-active.gif rename to views_ui/images/status-active.gif diff --git a/js/views-admin.js b/views_ui/js/views-admin.js similarity index 100% rename from js/views-admin.js rename to views_ui/js/views-admin.js diff --git a/lib/Drupal/views/ViewListController.php b/views_ui/lib/Drupal/views_ui/ViewListController.php similarity index 98% rename from lib/Drupal/views/ViewListController.php rename to views_ui/lib/Drupal/views_ui/ViewListController.php index f71a95f2d08a..5916ff811182 100644 --- a/lib/Drupal/views/ViewListController.php +++ b/views_ui/lib/Drupal/views_ui/ViewListController.php @@ -2,10 +2,10 @@ /** * @file - * Definition of Drupal\views\ViewListController. + * Definition of Drupal\views_ui\ViewListController. */ -namespace Drupal\views; +namespace Drupal\views_ui; use Drupal\Core\Entity\EntityListController; use Drupal\Core\Entity\EntityInterface; diff --git a/lib/Drupal/views/ViewUI.php b/views_ui/lib/Drupal/views_ui/ViewUI.php similarity index 97% rename from lib/Drupal/views/ViewUI.php rename to views_ui/lib/Drupal/views_ui/ViewUI.php index 91d7e90f01a8..5982ebbaca09 100644 --- a/lib/Drupal/views/ViewUI.php +++ b/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -2,11 +2,12 @@ /** * @file - * Definition of Drupal\views\ViewUI. + * Definition of Drupal\views_ui\ViewUI. */ -namespace Drupal\views; +namespace Drupal\views_ui; +use Drupal\views\ViewExecutable; use Drupal\views\TempStore\UserTempStore; /** @@ -392,7 +393,7 @@ public function buildOptionForm($id, $option, $display) { * Render the top of the display so it can be updated during ajax operations. */ public function renderDisplayTop($display_id) { - $element['#theme_wrappers'] = array('views_container'); + $element['#theme_wrappers'] = array('views_ui_container'); $element['#attributes']['class'] = array('views-display-top', 'clearfix'); $element['#attributes']['id'] = array('views-display-top'); @@ -939,7 +940,7 @@ public function getFormBucket($type, $display) { if (!$uses_fields) { $build['fields'][] = array( '#markup' => t('The selected style or row format does not utilize fields.'), - '#theme_wrappers' => array('views_container'), + '#theme_wrappers' => array('views_ui_container'), '#attributes' => array('class' => array('views-display-setting')), ); return $build; @@ -1149,7 +1150,7 @@ public function submitBreakLock(&$form, &$form_state) { drupal_set_message(t('The lock has been broken and you may now edit this view.')); } - public static function addForm($form, &$form_state) { + public static function buildAddForm($form, &$form_state) { $form['#attached']['css'] = static::getAdminCSS(); $form['#attached']['js'][] = drupal_get_path('module', 'views_ui') . '/js/views-admin.js'; $form['#attributes']['class'] = array('views-admin'); @@ -1242,7 +1243,7 @@ public static function addForm($form, &$form_state) { '#value' => t('Continue & edit'), '#validate' => array('views_ui_wizard_form_validate'), '#submit' => array('views_ui_add_form_store_edit_submit'), - '#process' => array_merge(array('views_ui_default_button'), element_info_property('submit', '#process', array())), + '#process' => array_merge(array(array(get_called_class(), 'processDefaultButton')), element_info_property('submit', '#process', array())), ); $form['cancel'] = array( '#type' => 'submit', @@ -1265,7 +1266,7 @@ public static function addForm($form, &$form_state) { * * @see views_ui_ajax_get_form() */ - public function editForm($form, &$form_state, $display_id = NULL) { + public function buildEditForm($form, &$form_state, $display_id = NULL) { // Do not allow the form to be cached, because $form_state['view'] can become // stale between page requests. // See views_ui_ajax_get_form() for how this affects #ajax. @@ -1487,7 +1488,7 @@ public function buildPreviewForm($form, &$form_state, $display_id = 'default') { // as this button, not the Save button. // @todo This only works for JS users. To make this work for nojs users, // we may need to split Preview into a separate form. - '#process' => array_merge(array('views_ui_default_button'), element_info_property('submit', '#process', array())), + '#process' => array_merge(array(array($this, 'processDefaultButton')), element_info_property('submit', '#process', array())), ); $form['#action'] = url('admin/structure/views/view/' . $this->storage->name .'/preview/' . $display_id); @@ -1613,7 +1614,7 @@ public function addFormToStack($key, $display_id, $args, $top = FALSE, $rebuild_ $this->stack = array(); } - $stack = array($this->buildIdentifier($key, $display_id, $args), $key, &$this, $display_id, $args); + $stack = array($this->buildIdentifier($key, $display_id, $args), $key, $display_id, $args); // If we're being asked to add this form to the bottom of the stack, no // special logic is required. Our work is equally easy if we were asked to add // to the top of the stack, but there's nothing in it yet. @@ -1964,4 +1965,43 @@ public static function sortPosition($display1, $display2) { return 0; } + /** + * Build up a $form_state object suitable for use with drupal_build_form + * based on known information about a form. + */ + public function buildFormState($js, $key, $display_id, $args) { + $form = views_ui_ajax_forms($key); + // Build up form state + $form_state = array( + 'form_key' => $key, + 'form_id' => $form['form_id'], + 'view' => &$this, + 'ajax' => $js, + 'display_id' => $display_id, + 'no_redirect' => TRUE, + ); + // If an method was specified, use that for the callback. + if (isset($form['callback'])) { + $form_state['build_info']['args'] = array(); + $form_state['build_info']['callback'] = array($this, $form['callback']); + } + + foreach ($form['args'] as $id) { + $form_state[$id] = (!empty($args)) ? array_shift($args) : NULL; + } + + return $form_state; + } + + /** + * #process callback for a button; makes implicit form submissions trigger as this button. + * + * @see Drupal.behaviors.viewsImplicitFormSubmission + */ + public static function processDefaultButton($element, &$form_state, $form) { + $setting['viewsImplicitFormSubmission'][$form['#id']]['defaultButton'] = $element['#id']; + $element['#attached']['js'][] = array('type' => 'setting', 'data' => $setting); + return $element; + } + } diff --git a/views_ui/theme/theme.inc b/views_ui/theme/theme.inc new file mode 100644 index 000000000000..c4dda8a4b83c --- /dev/null +++ b/views_ui/theme/theme.inc @@ -0,0 +1,513 @@ +<?php + +/** + * @file + * Preprocessors and theme functions for the Views UI. + */ + +use Drupal\Core\Template\Attribute; + +/** + * Generic <div> container function. + */ +function theme_views_ui_container($variables) { + $element = $variables['element']; + return '<div' . new Attribute($element['#attributes']) . '>' . $element['#children'] . '</div>'; +} + +function template_preprocess_views_ui_display_tab_setting(&$variables) { + static $zebra = 0; + $variables['zebra'] = ($zebra % 2 === 0 ? 'odd' : 'even'); + $zebra++; + + // Put the main link to the left side + array_unshift($variables['settings_links'], $variables['link']); + $variables['settings_links'] = implode('<span class="label"> | </span>', $variables['settings_links']); + + if (!empty($variables['defaulted'])) { + $variables['attributes']['class'][] = 'defaulted'; + } + if (!empty($variables['overridden'])) { + $variables['attributes']['class'][] = 'overridden'; + $variables['attributes_array']['title'][] = t('Overridden'); + } + + // Append a colon to the description, if requested. + if ($variables['description'] && $variables['description_separator']) { + $variables['description'] .= t(':'); + } +} + +function template_preprocess_views_ui_display_tab_bucket(&$variables) { + $element = $variables['element']; + + if (!empty($element['#name'])) { + $variables['attributes']['class'][] = drupal_html_class($element['#name']); + } + if (!empty($element['#overridden'])) { + $variables['attributes']['class'][] = 'overridden'; + $variables['attributes_array']['title'][] = t('Overridden'); + } + + $variables['content'] = $element['#children']; + $variables['title'] = $element['#title']; + $variables['actions'] = !empty($element['#actions']) ? $element['#actions'] : ''; +} + +/** + * Implements hook_preprocess_HOOK() for theme_views_ui_view_info(). + */ +function template_preprocess_views_ui_view_info(&$variables) { + $variables['title'] = $variables['view']->getHumanName(); + + $displays = $variables['view']->getDisplaysList(); + $variables['displays'] = empty($displays) ? t('None') : format_plural(count($displays), 'Display', 'Displays') . ': ' . '<em>' . implode(', ', $displays) . '</em>'; +} + +/** + * Returns basic administrative information about a view. + */ +function theme_views_ui_view_info($variables) { + $output = ''; + $output .= '<div class="views-ui-view-title">' . $variables['title'] . "</div>\n"; + $output .= '<div class="views-ui-view-displays">' . $variables['displays'] . "</div>\n"; + return $output; +} + +/** + * Theme the expose filter form. + */ +function theme_views_ui_expose_filter_form($variables) { + $form = $variables['form']; + $more = drupal_render($form['more']); + + $output = drupal_render($form['form_description']); + $output .= drupal_render($form['expose_button']); + $output .= drupal_render($form['group_button']); + if (isset($form['required'])) { + $output .= drupal_render($form['required']); + } + $output .= drupal_render($form['label']); + $output .= drupal_render($form['description']); + + $output .= drupal_render($form['operator']); + $output .= drupal_render($form['value']); + + if (isset($form['use_operator'])) { + $output .= '<div class="views-left-40">'; + $output .= drupal_render($form['use_operator']); + $output .= '</div>'; + } + + // Only output the right column markup if there's a left column to begin with + if (!empty($form['operator']['#type'])) { + $output .= '<div class="views-right-60">'; + $output .= drupal_render_children($form); + $output .= '</div>'; + } + else { + $output .= drupal_render_children($form); + } + + $output .= $more; + + return $output; +} + +/** + * Theme the build group filter form. + */ +function theme_views_ui_build_group_filter_form($variables) { + $form = $variables['form']; + $more = drupal_render($form['more']); + + $output = drupal_render($form['form_description']); + $output .= drupal_render($form['expose_button']); + $output .= drupal_render($form['group_button']); + if (isset($form['required'])) { + $output .= drupal_render($form['required']); + } + + $output .= drupal_render($form['operator']); + $output .= drupal_render($form['value']); + + $output .= '<div class="views-left-40">'; + $output .= drupal_render($form['optional']); + $output .= drupal_render($form['remember']); + $output .= '</div>'; + + $output .= '<div class="views-right-60">'; + $output .= drupal_render($form['widget']); + $output .= drupal_render($form['label']); + $output .= drupal_render($form['description']); + $output .= '</div>'; + + $header = array( + t('Default'), + t('Weight'), + t('Label'), + t('Operator'), + t('Value'), + t('Operations'), + ); + + $form['default_group'] = form_process_radios($form['default_group']); + $form['default_group_multiple'] = form_process_checkboxes($form['default_group_multiple']); + $form['default_group']['All']['#title'] = ''; + + hide($form['default_group_multiple']['All']); + $rows[] = array( + drupal_render($form['default_group']['All']), + '', + array( + 'data' => config('views.settings')->get('ui.exposed_filter_any_label') == 'old_any' ? t('<Any>') : t('- Any -'), + 'colspan' => 4, + 'class' => array('class' => 'any-default-radios-row'), + ), + ); + + foreach (element_children($form['group_items']) as $group_id) { + $form['group_items'][$group_id]['value']['#title'] = ''; + $data = array( + 'default' => drupal_render($form['default_group'][$group_id]) . drupal_render($form['default_group_multiple'][$group_id]), + 'weight' => drupal_render($form['group_items'][$group_id]['weight']), + 'title' => drupal_render($form['group_items'][$group_id]['title']), + 'operator' => drupal_render($form['group_items'][$group_id]['operator']), + 'value' => drupal_render($form['group_items'][$group_id]['value']), + 'remove' => drupal_render($form['group_items'][$group_id]['remove']) . l('<span>' . t('Remove') . '</span>', 'javascript:void()', array('attributes' => array('id' => 'views-remove-link-' . $group_id, 'class' => array('views-hidden', 'views-button-remove', 'views-groups-remove-link', 'views-remove-link'), 'alt' => t('Remove this item'), 'title' => t('Remove this item')), 'html' => true)), + ); + $rows[] = array('data' => $data, 'id' => 'views-row-' . $group_id, 'class' => array('draggable')); + } + $table = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('class' => array('views-filter-groups'), 'id' => 'views-filter-groups'))) . drupal_render($form['add_group']); + drupal_add_tabledrag('views-filter-groups', 'order', 'sibling', 'weight'); + $render_form = drupal_render_children($form); + return $output . $render_form . $table . $more; +} + +/** + * Turn the reorder form into a proper table + */ +function theme_views_ui_reorder_displays_form($vars) { + $form = $vars['form']; + $rows = array(); + foreach (element_children($form) as $key) { + if (isset($form[$key]['#display'])) { + $display = &$form[$key]; + + $row = array(); + $row[] = drupal_render($display['title']); + $form[$key]['weight']['#attributes']['class'] = array('weight'); + $row[] = drupal_render($form[$key]['weight']); + if (isset($display['removed'])) { + $row[] = drupal_render($form[$key]['removed']) . + l('<span>' . t('Remove') . '</span>', + 'javascript:void()', + array( + 'attributes' => array( + 'id' => 'display-remove-link-' . $key, + 'class' => array('views-button-remove display-remove-link'), + 'alt' => t('Remove this display'), + 'title' => t('Remove this display')), + 'html' => TRUE)); + } + else { + $row[] = ''; + } + $class = array(); + $styles = array(); + if (isset($form[$key]['weight']['#type'])) { + $class[] = 'draggable'; + } + if (isset($form[$key]['deleted']['#value']) && $form[$key]['deleted']['#value']) { + $styles[] = 'display: none;'; + } + $rows[] = array('data' => $row, 'class' => $class, 'id' => 'display-row-' . $key, 'style' => $styles); + } + } + + $header = array(t('Display'), t('Weight'), t('Remove')); + $output = ''; + drupal_add_tabledrag('reorder-displays', 'order', 'sibling', 'weight'); + + $output = drupal_render($form['override']); + $output .= '<div class="scroll">'; + $output .= theme('table', + array('header' => $header, + 'rows' => $rows, + 'attributes' => array('id' => 'reorder-displays'), + )); + $output .= '</div>'; + $output .= drupal_render_children($form); + + return $output; +} + +/** + * Turn the rearrange form into a proper table + */ +function theme_views_ui_rearrange_form($variables) { + $form = $variables['form']; + + $rows = array(); + foreach (element_children($form['fields']) as $id) { + if (isset($form['fields'][$id]['name'])) { + $row = array(); + $row[] = drupal_render($form['fields'][$id]['name']); + $form['fields'][$id]['weight']['#attributes']['class'] = array('weight'); + $row[] = drupal_render($form['fields'][$id]['weight']); + $row[] = drupal_render($form['fields'][$id]['removed']) . l('<span>' . t('Remove') . '</span>', 'javascript:void()', array('attributes' => array('id' => 'views-remove-link-' . $id, 'class' => array('views-hidden', 'views-button-remove', 'views-remove-link'), 'alt' => t('Remove this item'), 'title' => t('Remove this item')), 'html' => TRUE)); + $rows[] = array('data' => $row, 'class' => array('draggable'), 'id' => 'views-row-' . $id); + } + } + if (empty($rows)) { + $rows[] = array(array('data' => t('No fields available.'), 'colspan' => '2')); + } + + $header = array('', t('Weight'), t('Remove')); + $output = drupal_render($form['override']); + $output .= '<div class="scroll">'; + $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'arrange'))); + $output .= '</div>'; + $output .= drupal_render_children($form); + drupal_add_tabledrag('arrange', 'order', 'sibling', 'weight'); + + return $output; +} + +/** + * Turn the rearrange form into a proper table + */ +function theme_views_ui_rearrange_filter_form(&$vars) { + $form = $vars['form']; + $rows = $ungroupable_rows = array(); + // Enable grouping only if > 1 group. + $grouping = count(array_keys($form['#group_options'])) > 1; + + foreach ($form['#group_renders'] as $group_id => $contents) { + // Header row for the group. + if ($group_id !== 'ungroupable') { + // Set up tabledrag so that it changes the group dropdown when rows are + // dragged between groups. + drupal_add_tabledrag('views-rearrange-filters', 'match', 'sibling', 'views-group-select', 'views-group-select-' . $group_id); + + // Title row, spanning all columns. + $row = array(); + // Add a cell to the first row, containing the group operator. + $row[] = array('class' => array('group', 'group-operator', 'container-inline'), 'data' => drupal_render($form['filter_groups']['groups'][$group_id]), 'rowspan' => max(array(2, count($contents) + 1))); + // Title. + $row[] = array('class' => array('group', 'group-title'), 'data' => '<span>' . $form['#group_options'][$group_id] . '</span>', 'colspan' => 4); + $rows[] = array('class' => array('views-group-title'), 'data' => $row, 'id' => 'views-group-title-' . $group_id); + + // Row which will only appear if the group has nothing in it. + $row = array(); + $class = 'group-' . (count($contents) ? 'populated' : 'empty'); + $instructions = '<span>' . t('No filters have been added.') . '</span> <span class="js-only">' . t('Drag to add filters.') . '</span>'; + // When JavaScript is enabled, the button for removing the group (if it's + // present) should be hidden, since it will be replaced by a link on the + // client side. + if (!empty($form['remove_groups'][$group_id]['#type']) && $form['remove_groups'][$group_id]['#type'] == 'submit') { + $form['remove_groups'][$group_id]['#attributes']['class'][] = 'js-hide'; + } + $row[] = array('colspan' => 5, 'data' => $instructions . drupal_render($form['remove_groups'][$group_id])); + $rows[] = array('class' => array("group-message", "group-$group_id-message", $class), 'data' => $row, 'id' => 'views-group-' . $group_id); + } + + foreach ($contents as $id) { + if (isset($form['filters'][$id]['name'])) { + $row = array(); + $row[] = drupal_render($form['filters'][$id]['name']); + $form['filters'][$id]['weight']['#attributes']['class'] = array('weight'); + $row[] = drupal_render($form['filters'][$id]['weight']); + $form['filters'][$id]['group']['#attributes']['class'] = array('views-group-select views-group-select-' . $group_id); + $row[] = drupal_render($form['filters'][$id]['group']); + $form['filters'][$id]['removed']['#attributes']['class'][] = 'js-hide'; + $row[] = drupal_render($form['filters'][$id]['removed']) . l('<span>' . t('Remove') . '</span>', 'javascript:void()', array('attributes' => array('id' => 'views-remove-link-' . $id, 'class' => array('views-hidden', 'views-button-remove', 'views-groups-remove-link', 'views-remove-link'), 'alt' => t('Remove this item'), 'title' => t('Remove this item')), 'html' => TRUE)); + + $row = array('data' => $row, 'class' => array('draggable'), 'id' => 'views-row-' . $id); + if ($group_id !== 'ungroupable') { + $rows[] = $row; + } + else { + $ungroupable_rows[] = $row; + } + } + } + } + if (empty($rows)) { + $rows[] = array(array('data' => t('No fields available.'), 'colspan' => '2')); + } + + $output = drupal_render($form['override']); + $output .= '<div class="scroll">'; + if ($grouping) { + $output .= drupal_render($form['filter_groups']['operator']); + } + else { + $form['filter_groups']['groups'][0]['#title'] = t('Operator'); + $output .= drupal_render($form['filter_groups']['groups'][0]); + } + + if (!empty($ungroupable_rows)) { + drupal_add_tabledrag('views-rearrange-filters-ungroupable', 'order', 'sibling', 'weight'); + $header = array(t('Ungroupable filters'), t('Weight'), array('class' => array('views-hide-label'), 'data' => t('Group')), array('class' => array('views-hide-label'), 'data' => t('Remove'))); + $output .= theme('table', array('header' => $header, 'rows' => $ungroupable_rows, 'attributes' => array('id' => 'views-rearrange-filters-ungroupable', 'class' => array('arrange')))); + } + + // Set up tabledrag so that the weights are changed when rows are dragged. + drupal_add_tabledrag('views-rearrange-filters', 'order', 'sibling', 'weight'); + $output .= theme('table', array('rows' => $rows, 'attributes' => array('id' => 'views-rearrange-filters', 'class' => array('arrange')))); + $output .= '</div>'; + + // When JavaScript is enabled, the button for adding a new group should be + // hidden, since it will be replaced by a link on the client side. + $form['buttons']['add_group']['#attributes']['class'][] = 'js-hide'; + + // Render the rest of the form and return. + $output .= drupal_render_children($form); + return $output; +} + +/** + * Theme the form for the table style plugin + */ +function theme_views_ui_style_plugin_table($variables) { + $form = $variables['form']; + + $output = drupal_render($form['description_markup']); + + $header = array( + t('Field'), + t('Column'), + t('Align'), + t('Separator'), + array( + 'data' => t('Sortable'), + 'align' => 'center', + ), + array( + 'data' => t('Default order'), + 'align' => 'center', + ), + array( + 'data' => t('Default sort'), + 'align' => 'center', + ), + array( + 'data' => t('Hide empty column'), + 'align' => 'center', + ), + ); + $rows = array(); + foreach (element_children($form['columns']) as $id) { + $row = array(); + $row[] = drupal_render($form['info'][$id]['name']); + $row[] = drupal_render($form['columns'][$id]); + $row[] = drupal_render($form['info'][$id]['align']); + $row[] = drupal_render($form['info'][$id]['separator']); + if (!empty($form['info'][$id]['sortable'])) { + $row[] = array( + 'data' => drupal_render($form['info'][$id]['sortable']), + 'align' => 'center', + ); + $row[] = array( + 'data' => drupal_render($form['info'][$id]['default_sort_order']), + 'align' => 'center', + ); + $row[] = array( + 'data' => drupal_render($form['default'][$id]), + 'align' => 'center', + ); + } + else { + $row[] = ''; + $row[] = ''; + $row[] = ''; + } + $row[] = array( + 'data' => drupal_render($form['info'][$id]['empty_column']), + 'align' => 'center', + ); + $rows[] = $row; + } + + // Add the special 'None' row. + $rows[] = array(t('None'), '', '', '', '', '', array('align' => 'center', 'data' => drupal_render($form['default'][-1])), ''); + + $output .= theme('table', array('header' => $header, 'rows' => $rows)); + $output .= drupal_render_children($form); + return $output; +} + +/** + * Theme preprocess for theme_views_ui_view_preview_section(). + */ +function template_preprocess_views_ui_view_preview_section(&$vars) { + switch ($vars['section']) { + case 'title': + $vars['title'] = t('Title'); + $links = views_ui_view_preview_section_display_category_links($vars['view'], 'title', $vars['title']); + break; + case 'header': + $vars['title'] = t('Header'); + $links = views_ui_view_preview_section_handler_links($vars['view'], $vars['section']); + break; + case 'empty': + $vars['title'] = t('No results behavior'); + $links = views_ui_view_preview_section_handler_links($vars['view'], $vars['section']); + break; + case 'exposed': + // @todo Sorts can be exposed too, so we may need a better title. + $vars['title'] = t('Exposed Filters'); + $links = views_ui_view_preview_section_display_category_links($vars['view'], 'exposed_form_options', $vars['title']); + break; + case 'rows': + // @todo The title needs to depend on what is being viewed. + $vars['title'] = t('Content'); + $links = views_ui_view_preview_section_rows_links($vars['view']); + break; + case 'pager': + $vars['title'] = t('Pager'); + $links = views_ui_view_preview_section_display_category_links($vars['view'], 'pager_options', $vars['title']); + break; + case 'more': + $vars['title'] = t('More'); + $links = views_ui_view_preview_section_display_category_links($vars['view'], 'use_more', $vars['title']); + break; + case 'footer': + $vars['title'] = t('Footer'); + $links = views_ui_view_preview_section_handler_links($vars['view'], $vars['section']); + break; + case 'attachment_before': + // @todo: Add links to the attachment configuration page. + $vars['title'] = t('Attachment before'); + break; + case 'attachment_after': + // @todo: Add links to the attachment configuration page. + $vars['title'] = t('Attachment after'); + break; + } + + if (isset($links)) { + $build = array( + '#prefix' => '<div class="contextual">', + '#suffix' => '</div>', + '#theme' => 'links__contextual', + '#links' => $links, + '#attributes' => array('class' => array('contextual-links')), + '#attached' => array( + 'library' => array(array('contextual', 'contextual-links')), + ), + ); + $vars['links'] = drupal_render($build); + } + $vars['theme_hook_suggestions'][] = 'views_ui_view_preview_section__' . $vars['section']; +} + +/** + * Returns the HTML for a section of a View being previewed within the Views UI. + */ +function theme_views_ui_view_preview_section($vars) { + return '<h1 class="section-title">' . $vars['title'] . '</h1>' + . $vars['links'] + . '<div class="preview-section">'. $vars['content'] . '</div>'; +} diff --git a/theme/views-ui-display-tab-bucket.tpl.php b/views_ui/theme/views-ui-display-tab-bucket.tpl.php similarity index 100% rename from theme/views-ui-display-tab-bucket.tpl.php rename to views_ui/theme/views-ui-display-tab-bucket.tpl.php diff --git a/theme/views-ui-display-tab-setting.tpl.php b/views_ui/theme/views-ui-display-tab-setting.tpl.php similarity index 100% rename from theme/views-ui-display-tab-setting.tpl.php rename to views_ui/theme/views-ui-display-tab-setting.tpl.php diff --git a/theme/views-ui-edit-item.tpl.php b/views_ui/theme/views-ui-edit-item.tpl.php similarity index 100% rename from theme/views-ui-edit-item.tpl.php rename to views_ui/theme/views-ui-edit-item.tpl.php diff --git a/theme/views-ui-edit-view.tpl.php b/views_ui/theme/views-ui-edit-view.tpl.php similarity index 100% rename from theme/views-ui-edit-view.tpl.php rename to views_ui/theme/views-ui-edit-view.tpl.php diff --git a/views_ui.info b/views_ui/views_ui.info similarity index 100% rename from views_ui.info rename to views_ui/views_ui.info diff --git a/views_ui.module b/views_ui/views_ui.module similarity index 87% rename from views_ui.module rename to views_ui/views_ui.module index 87f6fdffc44a..c3b9d1faf7c2 100644 --- a/views_ui.module +++ b/views_ui/views_ui.module @@ -6,7 +6,7 @@ */ use Drupal\views\ViewExecutable; -use Drupal\views\ViewUI; +use Drupal\views_ui\ViewUI; use Drupal\views\Analyzer; use Drupal\Core\Entity\EntityInterface; use Symfony\Component\HttpFoundation\JsonResponse; @@ -21,7 +21,7 @@ function views_ui_menu() { $base = array( 'access callback' => 'user_access', 'access arguments' => array('administer views'), - 'file' => 'includes/admin.inc', + 'file' => 'admin.inc', ); // Set up the base for AJAX callbacks. $ajax_base = array( @@ -181,8 +181,7 @@ function views_ui_menu() { * Implements hook_theme(). */ function views_ui_theme() { - $path = drupal_get_path('module', 'views'); - require_once DRUPAL_ROOT . "/$path/includes/admin.inc"; + $path = drupal_get_path('module', 'views_ui'); return array( // edit a view @@ -190,11 +189,13 @@ function views_ui_theme() { 'variables' => array('description' => '', 'link' => '', 'settings_links' => array(), 'overridden' => FALSE, 'defaulted' => FALSE, 'description_separator' => TRUE, 'class' => array()), 'template' => 'views-ui-display-tab-setting', 'path' => "$path/theme", + 'file' => 'theme.inc', ), 'views_ui_display_tab_bucket' => array( 'render element' => 'element', 'template' => 'views-ui-display-tab-bucket', 'path' => "$path/theme", + 'file' => 'theme.inc', ), 'views_ui_edit_item' => array( 'variables' => array('type' => NULL, 'view' => NULL, 'display' => NULL, 'no_fields' => FALSE), @@ -203,26 +204,32 @@ function views_ui_theme() { ), 'views_ui_rearrange_form' => array( 'render element' => 'form', + 'path' => "$path/theme", + 'file' => 'theme.inc', ), 'views_ui_rearrange_filter_form' => array( 'render element' => 'form', - 'file' => 'includes/admin.inc', + 'path' => "$path/theme", + 'file' => 'theme.inc', ), 'views_ui_expose_filter_form' => array( 'render element' => 'form', - 'file' => 'includes/admin.inc', + 'path' => "$path/theme", + 'file' => 'theme.inc', ), // list views 'views_ui_view_info' => array( 'variables' => array('view' => NULL, 'base' => NULL), - 'file' => "includes/admin.inc", + 'path' => "$path/theme", + 'file' => 'theme.inc', ), // Group of filters. 'views_ui_build_group_filter_form' => array( 'render element' => 'form', - 'file' => 'includes/admin.inc', + 'path' => "$path/theme", + 'file' => 'theme.inc', ), // tab themes @@ -234,24 +241,30 @@ function views_ui_theme() { ), 'views_ui_reorder_displays_form' => array( 'render element' => 'form', - 'file' => 'includes/admin.inc', + 'path' => "$path/theme", + 'file' => 'theme.inc', ), // On behalf of a plugin 'views_ui_style_plugin_table' => array( 'render element' => 'form', + 'path' => "$path/theme", + 'file' => 'theme.inc', ), // When previewing a view. 'views_ui_view_preview_section' => array( 'variables' => array('view' => NULL, 'section' => NULL, 'content' => NULL, 'links' => ''), + 'path' => "$path/theme", + 'file' => 'theme.inc', ), // Generic container wrapper, to use instead of theme_container when an id // is not desired. - 'views_container' => array( + 'views_ui_container' => array( 'render element' => 'element', - 'file' => 'theme/theme.inc', + 'path' => "$path/theme", + 'file' => 'theme.inc', ), ); } @@ -275,7 +288,7 @@ function views_ui_custom_theme() { * Page title callback for the Edit View page. */ function views_ui_edit_page_title(ViewUI $view) { - module_load_include('inc', 'views_ui', 'includes/admin'); + module_load_include('inc', 'views_ui', 'admin'); $bases = views_fetch_base_tables(); $name = $view->storage->getHumanName(); if (isset($bases[$view->storage->base_table])) { @@ -368,7 +381,7 @@ function views_ui_preprocess_views_view(&$vars) { '#view' => $view, '#section' => $section, '#content' => is_array($vars[$section]) ? drupal_render($vars[$section]) : $vars[$section], - '#theme_wrappers' => array('views_container'), + '#theme_wrappers' => array('views_ui_container'), '#attributes' => array('class' => 'contextual-region'), ); $vars[$section] = drupal_render($vars[$section]); @@ -377,83 +390,6 @@ function views_ui_preprocess_views_view(&$vars) { } } -/** - * Theme preprocess for theme_views_ui_view_preview_section(). - * - * @TODO - * Perhaps move this to includes/admin.inc or theme/theme.inc - */ -function template_preprocess_views_ui_view_preview_section(&$vars) { - switch ($vars['section']) { - case 'title': - $vars['title'] = t('Title'); - $links = views_ui_view_preview_section_display_category_links($vars['view'], 'title', $vars['title']); - break; - case 'header': - $vars['title'] = t('Header'); - $links = views_ui_view_preview_section_handler_links($vars['view'], $vars['section']); - break; - case 'empty': - $vars['title'] = t('No results behavior'); - $links = views_ui_view_preview_section_handler_links($vars['view'], $vars['section']); - break; - case 'exposed': - // @todo Sorts can be exposed too, so we may need a better title. - $vars['title'] = t('Exposed Filters'); - $links = views_ui_view_preview_section_display_category_links($vars['view'], 'exposed_form_options', $vars['title']); - break; - case 'rows': - // @todo The title needs to depend on what is being viewed. - $vars['title'] = t('Content'); - $links = views_ui_view_preview_section_rows_links($vars['view']); - break; - case 'pager': - $vars['title'] = t('Pager'); - $links = views_ui_view_preview_section_display_category_links($vars['view'], 'pager_options', $vars['title']); - break; - case 'more': - $vars['title'] = t('More'); - $links = views_ui_view_preview_section_display_category_links($vars['view'], 'use_more', $vars['title']); - break; - case 'footer': - $vars['title'] = t('Footer'); - $links = views_ui_view_preview_section_handler_links($vars['view'], $vars['section']); - break; - case 'attachment_before': - // @todo: Add links to the attachment configuration page. - $vars['title'] = t('Attachment before'); - break; - case 'attachment_after': - // @todo: Add links to the attachment configuration page. - $vars['title'] = t('Attachment after'); - break; - } - - if (isset($links)) { - $build = array( - '#prefix' => '<div class="contextual">', - '#suffix' => '</div>', - '#theme' => 'links__contextual', - '#links' => $links, - '#attributes' => array('class' => array('contextual-links')), - '#attached' => array( - 'library' => array(array('contextual', 'contextual-links')), - ), - ); - $vars['links'] = drupal_render($build); - } - $vars['theme_hook_suggestions'][] = 'views_ui_view_preview_section__' . $vars['section']; -} - -/** - * Returns the HTML for a section of a View being previewed within the Views UI. - */ -function theme_views_ui_view_preview_section($vars) { - return '<h1 class="section-title">' . $vars['title'] . '</h1>' - . $vars['links'] - . '<div class="preview-section">'. $vars['content'] . '</div>'; -} - /** * Returns contextual links for each handler of a certain section. * -- GitLab