From 28f6c023c47e49697ca09c9a4888277c520f408f Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org> Date: Fri, 28 Feb 2014 10:23:03 +0000 Subject: [PATCH] Issue #2049209 by Cottser, dawehner, jibran, lokapujya, Manuel Garcia: Remove 'Theming information' feature from Views in favor of twig_debug. --- .../views/display/DisplayPluginBase.php | 259 ------------------ 1 file changed, 259 deletions(-) diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php index 47626aa3e5ce..db9eff1bb204 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php @@ -1361,13 +1361,6 @@ public function optionsSummary(&$categories, &$options) { 'desc' => t('Change the CSS class name(s) that will be added to this display.'), ); - $options['analyze-theme'] = array( - 'category' => 'other', - 'title' => t('Output'), - 'value' => t('Templates'), - 'desc' => t('Get information on how to theme this display'), - ); - foreach ($this->extender as $extender) { $extender->optionsSummary($categories, $options); } @@ -1773,202 +1766,6 @@ public function buildOptionsForm(&$form, &$form_state) { ), ); break; - case 'analyze-theme': - $form['#title'] .= t('Theming information'); - if ($theme = \Drupal::request()->request->get('theme')) { - $this->theme = $theme; - } - elseif (empty($this->theme)) { - $this->theme = \Drupal::config('system.theme')->get('default'); - } - - if (isset($GLOBALS['theme']) && $GLOBALS['theme'] == $this->theme) { - $this->theme_registry = \Drupal::service('theme.registry')->get(); - $theme_engine = $GLOBALS['theme_engine']; - } - else { - $themes = list_themes(); - $theme = $themes[$this->theme]; - - // @see _drupal_theme_initialize() - $theme_engine = NULL; - - if (isset($theme->engine)) { - $theme_engine = $theme->engine; - } - $cache_theme = \Drupal::service('cache.theme'); - $this->theme_registry = new Registry($cache_theme, \Drupal::lock(), \Drupal::moduleHandler(), $theme->name); - } - - // If there's a theme engine involved, we also need to know its extension - // so we can give the proper filename. - $this->theme_extension = '.html.twig'; - if (isset($theme_engine)) { - $extension_function = $theme_engine . '_extension'; - if (function_exists($extension_function)) { - $this->theme_extension = $extension_function(); - } - } - - $funcs = array(); - // Get theme functions for the display. Note that some displays may - // not have themes. The 'feed' display, for example, completely - // delegates to the style. - if (!empty($this->definition['theme'])) { - $funcs[] = $this->optionLink(t('Display output'), 'analyze-theme-display') . ': ' . $this->formatThemes($this->themeFunctions()); - } - - $plugin = $this->getPlugin('style'); - if ($plugin) { - $funcs[] = $this->optionLink(t('Style output'), 'analyze-theme-style') . ': ' . $this->formatThemes($plugin->themeFunctions()); - - if ($plugin->usesRowPlugin()) { - $row_plugin = $this->getPlugin('row'); - if ($row_plugin) { - $funcs[] = $this->optionLink(t('Row style output'), 'analyze-theme-row') . ': ' . $this->formatThemes($row_plugin->themeFunctions()); - } - } - - if ($plugin->usesFields()) { - foreach ($this->getHandlers('field') as $id => $handler) { - $funcs[] = $this->optionLink(t('Field @field (ID: @id)', array('@field' => $handler->adminLabel(), '@id' => $id)), 'analyze-theme-field') . ': ' . $this->formatThemes($handler->themeFunctions()); - } - } - } - - $form['important'] = array( - '#markup' => '<div class="form-item description"><p>' . t('This section lists all possible templates for the display plugin and for the style plugins, ordered roughly from the least specific to the most specific. The active template for each plugin -- which is the most specific template found on the system -- is highlighted in bold.') . '</p></div>', - ); - - if (isset($this->view->display_handler->new_id)) { - $form['important']['new_id'] = array( - '#prefix' => '<div class="description">', - '#suffix' => '</div>', - '#value' => t("<strong>Important!</strong> You have changed the display's machine name. Anything that attached to this display specifically, such as theming, may stop working until it is updated. To see theme suggestions for it, you need to save the view."), - ); - } - - foreach (list_themes() as $key => $theme) { - if (!empty($theme->info['hidden'])) { - continue; - } - $options[$key] = $theme->info['name']; - } - - $form['box'] = array( - '#prefix' => '<div class="container-inline">', - '#suffix' => '</div>', - ); - $form['box']['theme'] = array( - '#title' => t('Theme'), - '#title_display' => 'invisible', - '#type' => 'select', - '#options' => $options, - '#default_value' => $this->theme, - ); - - $form['box']['change'] = array( - '#type' => 'submit', - '#value' => t('Change theme'), - '#submit' => array(array($this, 'changeThemeForm')), - ); - - $form['analysis'] = array( - '#theme' => 'item_list', - '#prefix' => '<div class="form-item">', - '#items' => $funcs, - '#suffix' => '</div>', - ); - - $form['rescan_button'] = array( - '#prefix' => '<div class="form-item">', - '#suffix' => '</div>', - ); - $form['rescan_button']['button'] = array( - '#type' => 'submit', - '#value' => t('Rescan template files'), - '#submit' => array(array($this, 'rescanThemes')), - ); - $form['rescan_button']['markup'] = array( - '#markup' => '<div class="description">' . t("<strong>Important!</strong> When adding, removing, or renaming template files, it is necessary to make Drupal aware of the changes by making it rescan the files on your system. By clicking this button you clear Drupal's theme registry and thereby trigger this rescanning process. The highlighted templates above will then reflect the new state of your system.") . '</div>', - ); - - $form_state['ok_button'] = TRUE; - break; - case 'analyze-theme-display': - $form['#title'] .= t('Theming information (display)'); - $output = '<p>' . t('Back to !info.', array('!info' => $this->optionLink(t('theming information'), 'analyze-theme'))) . '</p>'; - - if (empty($this->definition['theme'])) { - $output .= t('This display has no theming information'); - } - else { - $output .= '<p>' . t('This is the default theme template used for this display.') . '</p>'; - $output .= '<pre>' . String::checkPlain(file_get_contents('./' . $this->definition['theme_path'] . '/' . strtr($this->definition['theme'], '_', '-') . '.tpl.php')) . '</pre>'; - } - - $form['analysis'] = array( - '#markup' => '<div class="form-item">' . $output . '</div>', - ); - - $form_state['ok_button'] = TRUE; - break; - case 'analyze-theme-style': - $form['#title'] .= t('Theming information (style)'); - $output = '<p>' . t('Back to !info.', array('!info' => $this->optionLink(t('theming information'), 'analyze-theme'))) . '</p>'; - - $plugin = $this->getPlugin('style'); - - if (empty($plugin->definition['theme'])) { - $output .= t('This display has no style theming information'); - } - else { - $output .= '<p>' . t('This is the default theme template used for this style.') . '</p>'; - $output .= '<pre>' . String::checkPlain(file_get_contents('./' . $plugin->definition['theme_path'] . '/' . strtr($plugin->definition['theme'], '_', '-') . '.tpl.php')) . '</pre>'; - } - - $form['analysis'] = array( - '#markup' => '<div class="form-item">' . $output . '</div>', - ); - - $form_state['ok_button'] = TRUE; - break; - case 'analyze-theme-row': - $form['#title'] .= t('Theming information (row style)'); - $output = '<p>' . t('Back to !info.', array('!info' => $this->optionLink(t('theming information'), 'analyze-theme'))) . '</p>'; - - $plugin = $this->getPlugin('row'); - - if (empty($plugin->definition['theme'])) { - $output .= t('This display has no row style theming information'); - } - else { - $output .= '<p>' . t('This is the default theme template used for this row style.') . '</p>'; - $output .= '<pre>' . String::checkPlain(file_get_contents('./' . $plugin->definition['theme_path'] . '/' . strtr($plugin->definition['theme'], '_', '-') . '.tpl.php')) . '</pre>'; - } - - $form['analysis'] = array( - '#markup' => '<div class="form-item">' . $output . '</div>', - ); - - $form_state['ok_button'] = TRUE; - break; - case 'analyze-theme-field': - $form['#title'] .= t('Theming information (row style)'); - $output = '<p>' . t('Back to !info.', array('!info' => $this->optionLink(t('theming information'), 'analyze-theme'))) . '</p>'; - - $output .= '<p>' . t('This is the default theme template used for this row style.') . '</p>'; - - // Field templates aren't registered the normal way...and they're always - // this one, anyhow. - $output .= '<pre>' . String::checkPlain(file_get_contents(drupal_get_path('module', 'views') . '/templates/views-view-field.tpl.php')) . '</pre>'; - - $form['analysis'] = array( - '#markup' => '<div class="form-item">' . $output . '</div>', - ); - $form_state['ok_button'] = TRUE; - break; - case 'exposed_block': $form['#title'] .= t('Put the exposed form in a block'); $form['description'] = array( @@ -2060,62 +1857,6 @@ public function buildOptionsForm(&$form, &$form_state) { } } - /** - * Submit hook to clear Drupal's theme registry (thereby triggering - * a templates rescan). - */ - public function rescanThemes($form, &$form_state) { - // Analyzes the data of the theme registry. - \Drupal::service('theme.registry')->reset(); - - drupal_theme_initialize(); - - $form_state['rerender'] = TRUE; - $form_state['rebuild'] = TRUE; - } - - /** - * Displays the Change Theme form. - */ - public function changeThemeForm($form, &$form_state) { - // This is just a temporary variable. - $form_state['view']->theme = $form_state['values']['theme']; - - $form_state['view']->cacheSet(); - $form_state['rerender'] = TRUE; - $form_state['rebuild'] = TRUE; - } - - /** - * Format a list of theme templates for output by the theme info helper. - */ - protected function formatThemes($themes) { - $registry = $this->theme_registry; - $extension = $this->theme_extension; - - $picked = FALSE; - foreach ($themes as $theme) { - $template = strtr($theme, '_', '-') . $extension; - if (!$picked && !empty($registry[$theme])) { - $template_path = isset($registry[$theme]['path']) ? $registry[$theme]['path'] . '/' : './'; - if (file_exists($template_path . $template)) { - $hint = t('File found in folder @template-path', array('@template-path' => $template_path)); - $template = '<strong title="'. $hint .'">' . $template . '</strong>'; - } - else { - $template = '<strong class="error">' . $template . ' ' . t('(File not found, in folder @template-path)', array('@template-path' => $template_path)) . '</strong>'; - } - $picked = TRUE; - } - $fixed[] = $template; - } - $item_list = array( - '#theme' => 'item_list', - '#items' => array_reverse($fixed), - ); - return drupal_render($item_list); - } - /** * Validate the options form. */ -- GitLab