Issue #2027031 by damiankloip: Move views_theme_functions() to ViewExecutable method.
parent
4b2249807f
commit
fc9584d55a
|
@ -207,7 +207,7 @@ abstract class PluginBase extends ContainerFactoryPluginBase {
|
|||
* Provide a full list of possible theme templates used by this style.
|
||||
*/
|
||||
public function themeFunctions() {
|
||||
return views_theme_functions($this->definition['theme'], $this->view, $this->view->display_handler->display);
|
||||
return $this->view->buildThemeFunctions($this->definition['theme']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2452,7 +2452,7 @@ abstract class DisplayPluginBase extends PluginBase {
|
|||
if (!empty($this->view->exposed_raw_input)) {
|
||||
$url_options['query'] = $this->view->exposed_raw_input;
|
||||
}
|
||||
$theme = views_theme_functions('views_more', $this->view, $this->view->display_handler->display);
|
||||
$theme = $this->view->buildThemeFunctions('views_more');
|
||||
$path = check_url(url($path, $url_options));
|
||||
|
||||
return theme($theme, array('more_url' => $path, 'link_text' => check_plain($this->useMoreText()), 'view' => $this->view));
|
||||
|
|
|
@ -81,7 +81,7 @@ class Full extends SqlBase {
|
|||
* Overrides \Drupal\views\Plugin\views\pager\PagerPluginBase::render().
|
||||
*/
|
||||
function render($input) {
|
||||
$pager_theme = views_theme_functions('pager', $this->view, $this->view->display_handler->display);
|
||||
$pager_theme = $this->view->buildThemeFunctions('pager');
|
||||
// The 0, 1, 3, 4 index are correct. See theme_pager documentation.
|
||||
$tags = array(
|
||||
0 => $this->options['tags']['first'],
|
||||
|
|
|
@ -457,7 +457,7 @@ abstract class StylePluginBase extends PluginBase {
|
|||
*/
|
||||
public function renderGroupingSets($sets, $level = 0) {
|
||||
$output = array();
|
||||
$theme_functions = views_theme_functions($this->groupingTheme, $this->view, $this->view->display_handler->display);
|
||||
$theme_functions = $this->view->buildThemeFunctions($this->groupingTheme);
|
||||
foreach ($sets as $set) {
|
||||
$row = reset($set['rows']);
|
||||
// Render as a grouping set.
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\views\Tests\ViewExecutableTest.
|
||||
* Contains \Drupal\views\Tests\ViewExecutableUnitTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\views\Tests;
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace Drupal\views;
|
|||
use Drupal;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Drupal\views\ViewStorageInterface;
|
||||
use Drupal\Component\Utility\Tags;
|
||||
|
||||
/**
|
||||
* @defgroup views_objects Objects that represent a View or part of a view
|
||||
|
@ -2111,4 +2112,37 @@ class ViewExecutable {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a full array of possible theme functions to try for a given hook.
|
||||
*
|
||||
* @param string $hook
|
||||
* The hook to use. This is the base theme/template name.
|
||||
*
|
||||
* @return array
|
||||
* An array of theme hook suggestions.
|
||||
*/
|
||||
public function buildThemeFunctions($hook) {
|
||||
$themes = array();
|
||||
$display = isset($this->display_handler) ? $this->display_handler->display : NULL;
|
||||
$id = $this->storage->id();
|
||||
|
||||
if ($display) {
|
||||
$themes[] = $hook . '__' . $id . '__' . $display['id'];
|
||||
$themes[] = $hook . '__' . $display['id'];
|
||||
// Add theme suggestions for each single tag.
|
||||
foreach (Tags::explode($this->storage->get('tag')) as $tag) {
|
||||
$themes[] = $hook . '__' . preg_replace('/[^a-z0-9]/', '_', strtolower($tag));
|
||||
}
|
||||
|
||||
if ($display['id'] != $display['display_plugin']) {
|
||||
$themes[] = $hook . '__' . $id . '__' . $display['display_plugin'];
|
||||
$themes[] = $hook . '__' . $display['display_plugin'];
|
||||
}
|
||||
}
|
||||
$themes[] = $hook . '__' . $id;
|
||||
$themes[] = $hook;
|
||||
|
||||
return $themes;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\views\Tests\ViewExecutableUnitTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\views\Tests;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\views\Plugin\Core\Entity\View;
|
||||
use Drupal\views\ViewExecutable;
|
||||
|
||||
/**
|
||||
* Tests methods on the ViewExecutable class.
|
||||
*
|
||||
* @see \Drupal\views\ViewExecutable
|
||||
*/
|
||||
class ViewExecutableUnitTest extends UnitTestCase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'View executable test',
|
||||
'description' => 'Tests methods on the \Drupal\views\ViewExecutable class',
|
||||
'group' => 'Views',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the buildThemeFunctions() method.
|
||||
*/
|
||||
public function testBuildThemeFunctions() {
|
||||
$config = array(
|
||||
'id' => 'test_view',
|
||||
'tag' => 'OnE, TWO, and three',
|
||||
'display' => array(
|
||||
'default' => array(
|
||||
'id' => 'default',
|
||||
'display_plugin' => 'default',
|
||||
'display_title' => 'Default',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$storage = new View($config, 'view');
|
||||
$view = new ViewExecutable($storage);
|
||||
|
||||
$expected = array(
|
||||
'test_hook__test_view',
|
||||
'test_hook'
|
||||
);
|
||||
$this->assertEquals($expected, $view->buildThemeFunctions('test_hook'));
|
||||
|
||||
// Add a mock display.
|
||||
$display = $this->getMockBuilder('Drupal\views\Plugin\views\display\DisplayPluginBase')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$display->display = $config['display']['default'];
|
||||
$view->display_handler = $display;
|
||||
|
||||
$expected = array(
|
||||
'test_hook__test_view__default',
|
||||
'test_hook__default',
|
||||
'test_hook__one',
|
||||
'test_hook__two',
|
||||
'test_hook__and_three',
|
||||
'test_hook__test_view',
|
||||
'test_hook'
|
||||
);
|
||||
$this->assertEquals($expected, $view->buildThemeFunctions('test_hook'));
|
||||
|
||||
//Change the name of the display plugin and make sure that is in the array.
|
||||
$view->display_handler->display['display_plugin'] = 'default2';
|
||||
|
||||
$expected = array(
|
||||
'test_hook__test_view__default',
|
||||
'test_hook__default',
|
||||
'test_hook__one',
|
||||
'test_hook__two',
|
||||
'test_hook__and_three',
|
||||
'test_hook__test_view__default2',
|
||||
'test_hook__default2',
|
||||
'test_hook__test_view',
|
||||
'test_hook'
|
||||
);
|
||||
$this->assertEquals($expected, $view->buildThemeFunctions('test_hook'));
|
||||
}
|
||||
|
||||
}
|
|
@ -1360,7 +1360,7 @@ function views_exposed_form($form, &$form_state) {
|
|||
);
|
||||
|
||||
$form['#action'] = url($view->display_handler->getUrl());
|
||||
$form['#theme'] = views_theme_functions('views_exposed_form', $view, $display);
|
||||
$form['#theme'] = $view->buildThemeFunctions('views_exposed_form');
|
||||
$form['#id'] = drupal_clean_css_identifier('views_exposed_form-' . check_plain($view->storage->id()) . '-' . check_plain($display['id']));
|
||||
// $form['#attributes']['class'] = array('views-exposed-form');
|
||||
|
||||
|
@ -1450,14 +1450,6 @@ function views_exposed_form_cache($views_name, $display_name, $form_output = NUL
|
|||
return empty($views_exposed[$views_name][$display_name]) ? FALSE : $views_exposed[$views_name][$display_name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a list of theme function names for use most everywhere.
|
||||
*/
|
||||
function views_theme_functions($hook, ViewExecutable $view, $display = NULL) {
|
||||
Drupal::moduleHandler()->loadInclude('views', 'inc', 'views.theme');
|
||||
return _views_theme_functions($hook, $view, $display);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_query_TAG_alter().
|
||||
*
|
||||
|
|
|
@ -10,37 +10,6 @@ use Drupal\Core\Language\Language;
|
|||
use Drupal\Core\Template\Attribute;
|
||||
use Drupal\views\ViewExecutable;
|
||||
|
||||
/**
|
||||
* Provide a full array of possible themes to try for a given hook.
|
||||
*
|
||||
* @param string $hook
|
||||
* The hook to use. This is the base theme/template name.
|
||||
* @param \Drupal\views\ViewExecutable $view
|
||||
* The view being rendered.
|
||||
* @param string|null $display
|
||||
* The display being rendered, if applicable.
|
||||
*/
|
||||
function _views_theme_functions($hook, ViewExecutable $view, $display = NULL) {
|
||||
$themes = array();
|
||||
|
||||
if ($display) {
|
||||
$themes[] = $hook . '__' . $view->storage->id() . '__' . $display['id'];
|
||||
$themes[] = $hook . '__' . $display['id'];
|
||||
// Add theme suggestions for each single tag.
|
||||
foreach (drupal_explode_tags($view->storage->get('tag')) as $tag) {
|
||||
$themes[] = $hook . '__' . preg_replace('/[^a-z0-9]/', '_', strtolower($tag));
|
||||
}
|
||||
|
||||
if ($display['id'] != $display['display_plugin']) {
|
||||
$themes[] = $hook . '__' . $view->storage->id() . '__' . $display['display_plugin'];
|
||||
$themes[] = $hook . '__' . $display['display_plugin'];
|
||||
}
|
||||
}
|
||||
$themes[] = $hook . '__' . $view->storage->id();
|
||||
$themes[] = $hook;
|
||||
return $themes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares variables for view templates.
|
||||
*
|
||||
|
@ -1252,6 +1221,6 @@ function theme_views_mini_pager($vars) {
|
|||
* Important! When adding a new template to your theme, be sure to flush the
|
||||
* theme registry cache!
|
||||
*
|
||||
* @see _views_theme_functions()
|
||||
* @see \Drupal\views\ViewExecutable::buildThemeFunctions()
|
||||
* @}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue