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 5cae913..5c69d52 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 @@ -1750,6 +1750,7 @@ public function buildOptionsForm(&$form, &$form_state) { ); break; case 'analyze-theme': + $this->getThemeInformation(); $form['#title'] .= t('Theming information'); if ($theme = \Drupal::request()->request->get('theme')) { $this->theme = $theme; @@ -1905,6 +1906,7 @@ public function buildOptionsForm(&$form, &$form_state) { $form_state['ok_button'] = TRUE; break; case 'analyze-theme-display': + $this->getThemeInformation(); $form['#title'] .= t('Theming information (display)'); $output = '

' . t('Back to !info.', array('!info' => $this->optionLink(t('theming information'), 'analyze-theme'))) . '

'; @@ -1913,7 +1915,7 @@ public function buildOptionsForm(&$form, &$form_state) { } else { $output .= '

' . t('This is the default theme template used for this display.') . '

'; - $output .= '
' . check_plain(file_get_contents('./' . $this->definition['theme_path'] . '/' . strtr($this->definition['theme'], '_', '-') . '.tpl.php')) . '
'; + $output .= '
' . check_plain(file_get_contents('./' . $this->definition['theme_path'] . '/' . strtr($this->definition['theme'], '_', '-') . $this->theme_extension)) . '
'; } $form['analysis'] = array( @@ -1923,6 +1925,7 @@ public function buildOptionsForm(&$form, &$form_state) { $form_state['ok_button'] = TRUE; break; case 'analyze-theme-style': + $this->getThemeInformation(); $form['#title'] .= t('Theming information (style)'); $output = '

' . t('Back to !info.', array('!info' => $this->optionLink(t('theming information'), 'analyze-theme'))) . '

'; @@ -1933,7 +1936,7 @@ public function buildOptionsForm(&$form, &$form_state) { } else { $output .= '

' . t('This is the default theme template used for this style.') . '

'; - $output .= '
' . check_plain(file_get_contents('./' . $plugin->definition['theme_path'] . '/' . strtr($plugin->definition['theme'], '_', '-') . '.tpl.php')) . '
'; + $output .= '
' . check_plain(file_get_contents('./' . $plugin->definition['theme_path'] . '/' . strtr($plugin->definition['theme'], '_', '-') . $this->theme_extension)) . '
'; } $form['analysis'] = array( @@ -1943,6 +1946,7 @@ public function buildOptionsForm(&$form, &$form_state) { $form_state['ok_button'] = TRUE; break; case 'analyze-theme-row': + $this->getThemeInformation(); $form['#title'] .= t('Theming information (row style)'); $output = '

' . t('Back to !info.', array('!info' => $this->optionLink(t('theming information'), 'analyze-theme'))) . '

'; @@ -1953,7 +1957,7 @@ public function buildOptionsForm(&$form, &$form_state) { } else { $output .= '

' . t('This is the default theme template used for this row style.') . '

'; - $output .= '
' . check_plain(file_get_contents('./' . $plugin->definition['theme_path'] . '/' . strtr($plugin->definition['theme'], '_', '-') . '.tpl.php')) . '
'; + $output .= '
' . check_plain(file_get_contents('./' . $plugin->definition['theme_path'] . '/' . strtr($plugin->definition['theme'], '_', '-') . $this->theme_extension)) . '
'; } $form['analysis'] = array( @@ -1963,6 +1967,7 @@ public function buildOptionsForm(&$form, &$form_state) { $form_state['ok_button'] = TRUE; break; case 'analyze-theme-field': + $this->getThemeInformation(); $form['#title'] .= t('Theming information (row style)'); $output = '

' . t('Back to !info.', array('!info' => $this->optionLink(t('theming information'), 'analyze-theme'))) . '

'; @@ -1970,7 +1975,7 @@ public function buildOptionsForm(&$form, &$form_state) { // Field templates aren't registered the normal way...and they're always // this one, anyhow. - $output .= '
' . check_plain(file_get_contents(drupal_get_path('module', 'views') . '/templates/views-view-field.tpl.php')) . '
'; + $output .= '
' . check_plain(file_get_contents(drupal_get_path('module', 'views') . '/templates/views-view-field' . $this->theme_extension)) . '
'; $form['analysis'] = array( '#markup' => '
' . $output . '
', @@ -2852,6 +2857,79 @@ protected function mergeHandler($type) { $this->setOption($types[$type]['plural'], $options); } + /** + * Gets information about the current theme or a specific theme. + */ + protected function getThemeInformation() { + if ($theme = drupal_container()->get('request')->request->get('theme')) { + $this->theme = $theme; + } + elseif (empty($this->theme)) { + $this->theme = config('system.theme')->get('default'); + } + + if (isset($GLOBALS['theme']) && $GLOBALS['theme'] == $this->theme) { + $this->theme_registry = theme_get_registry(); + $theme_engine = $GLOBALS['theme_engine']; + } + else { + $themes = list_themes(); + $theme = $themes[$this->theme]; + + // Find all our ancestor themes and put them in an array. + $base_theme = array(); + $ancestor = $this->theme; + while ($ancestor && isset($themes[$ancestor]->base_theme)) { + $ancestor = $themes[$ancestor]->base_theme; + $base_theme[] = $themes[$ancestor]; + } + + // The base themes should be initialized in the right order. + $base_theme = array_reverse($base_theme); + + // This code is copied directly from _drupal_theme_initialize() + $theme_engine = NULL; + + // Initialize the theme. + if (isset($theme->engine)) { + // Include the engine. + include_once DRUPAL_ROOT . '/' . $theme->owner; + + $theme_engine = $theme->engine; + if (function_exists($theme_engine . '_init')) { + foreach ($base_theme as $base) { + call_user_func($theme_engine . '_init', $base); + } + call_user_func($theme_engine . '_init', $theme); + } + } + else { + // include non-engine theme files + foreach ($base_theme as $base) { + // Include the theme file or the engine. + if (!empty($base->owner)) { + include_once DRUPAL_ROOT . '/' . $base->owner; + } + } + // and our theme gets one too. + if (!empty($theme->owner)) { + include_once DRUPAL_ROOT . '/' . $theme->owner; + } + } + $this->theme_registry = _theme_load_registry($theme, $base_theme, $theme_engine); + } + + // 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(); + } + } + } + } /**