Commit 491bd633 authored by webchick's avatar webchick
Browse files

Issue #1987870 by disasm: Convert theme_test() callbacks to a new style controller.

parent 0aa6f4e5
...@@ -7,28 +7,89 @@ ...@@ -7,28 +7,89 @@
namespace Drupal\theme_test; namespace Drupal\theme_test;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Controller routines for theme test routes. * Controller routines for theme test routes.
*/ */
class ThemeTestController implements ContainerInjectionInterface { class ThemeTestController extends ControllerBase {
/** /**
* {@inheritdoc} * A theme template that overrides a theme function.
*
* @return array
* Render array containing a theme.
*/ */
public static function create(ContainerInterface $container) { public function functionTemplateOverridden() {
return new static(); return array(
'#theme' => 'theme_test_function_template_override',
);
} }
/** /**
* Menu callback for testing that a theme template overrides a theme function. * Adds stylesheets to test theme .info.yml property processing.
*
* @return array
* A render array containing custom stylesheets.
*/ */
function functionTemplateOverridden() { public function testInfoStylesheets() {
$path = drupal_get_path('module', 'theme_test');
return array( return array(
'#theme' => 'theme_test_function_template_override', '#attached' => array(
'css' => array(
"$path/css/base-override.css",
"$path/css/base-override.sub-remove.css",
"$path/css/base-remove.css",
"$path/css/base-remove.sub-override.css",
"$path/css/sub-override.css",
"$path/css/sub-remove.css",
),
),
); );
} }
/**
* Tests template overridding based on filename.
*
* @return array
* A render array containing a theme override.
*/
public function testTemplate() {
return theme('theme_test_template_test');
}
/**
* Calls a theme hook suggestion.
*
* @return string
* An HTML string containing the themed output.
*/
public function testSuggestion() {
return theme(array('theme_test__suggestion', 'theme_test'), array());
}
/**
* This is for testing that the theme can have hook_*_alter() implementations
* that run during page callback execution, even before theme() is called for
* the first time.
*
* @return string
* A string containing the altered data.
*/
public function testAlter() {
$data = 'foo';
$this->moduleHandler()->alter('theme_test_alter', $data);
return "The altered data is $data.";
}
/**
* Tests themed output generated in a request listener.
*
* @return string
* Content in theme_test_output GLOBAL.
*/
public function testRequestListener() {
return $GLOBALS['theme_test_output'];
}
} }
...@@ -46,32 +46,13 @@ function theme_test_system_theme_info() { ...@@ -46,32 +46,13 @@ function theme_test_system_theme_info() {
*/ */
function theme_test_menu() { function theme_test_menu() {
$items['theme-test/suggestion'] = array( $items['theme-test/suggestion'] = array(
'title' => 'Suggestion', 'route_name' => 'theme_test_suggestion',
'page callback' => '_theme_test_suggestion',
'access callback' => TRUE,
'theme callback' => '_theme_custom_theme', 'theme callback' => '_theme_custom_theme',
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
); );
$items['theme-test/alter'] = array( $items['theme-test/alter'] = array(
'title' => 'Suggestion',
'page callback' => '_theme_test_alter',
'access callback' => TRUE,
'theme callback' => '_theme_custom_theme', 'theme callback' => '_theme_custom_theme',
'type' => MENU_CALLBACK, 'route_name' => 'theme_test_alter',
);
$items['theme-test/request-listener'] = array(
'page callback' => 'theme_test_request_listener_page_callback',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['theme-test/template-test'] = array(
'page callback' => 'theme_test_template_test_page_callback',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['theme-test/info/stylesheets'] = array(
'page callback' => 'theme_test_info_stylesheets',
'access callback' => TRUE,
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
); );
$items['theme-test/function-template-overridden'] = array( $items['theme-test/function-template-overridden'] = array(
...@@ -80,7 +61,6 @@ function theme_test_menu() { ...@@ -80,7 +61,6 @@ function theme_test_menu() {
); );
return $items; return $items;
} }
/** /**
* Fake registry loading callback. * Fake registry loading callback.
*/ */
...@@ -89,39 +69,6 @@ function _theme_test_load_registry() { ...@@ -89,39 +69,6 @@ function _theme_test_load_registry() {
return array(); return array();
} }
/**
* Menu callback for testing themed output generated in a request listener.
*/
function theme_test_request_listener_page_callback() {
return $GLOBALS['theme_test_output'];
}
/**
* Menu callback for testing template overridding based on filename.
*/
function theme_test_template_test_page_callback() {
return theme('theme_test_template_test');
}
/**
* Page callback; Adds stylesheets to test theme .info.yml property processing.
*
* @see test_basetheme.info.yml
* @see test_subtheme.info.yml
* @see \Drupal\system\Tests\Theme\ThemeInfoStylesTest
* @see http://drupal.org/node/967266#comment-3689670
*/
function theme_test_info_stylesheets() {
$path = drupal_get_path('module', 'theme_test');
drupal_add_css("$path/css/base-override.css");
drupal_add_css("$path/css/base-override.sub-remove.css");
drupal_add_css("$path/css/base-remove.css");
drupal_add_css("$path/css/base-remove.sub-override.css");
drupal_add_css("$path/css/sub-override.css");
drupal_add_css("$path/css/sub-remove.css");
return '';
}
/** /**
* Custom theme callback. * Custom theme callback.
*/ */
...@@ -129,26 +76,6 @@ function _theme_custom_theme() { ...@@ -129,26 +76,6 @@ function _theme_custom_theme() {
return 'test_theme'; return 'test_theme';
} }
/**
* Page callback, calls drupal_alter().
*
* This is for testing that the theme can have hook_*_alter() implementations
* that run during page callback execution, even before theme() is called for
* the first time.
*/
function _theme_test_alter() {
$data = 'foo';
drupal_alter('theme_test_alter', $data);
return "The altered data is $data.";
}
/**
* Page callback, calls a theme hook suggestion.
*/
function _theme_test_suggestion() {
return theme(array('theme_test__suggestion', 'theme_test'), array());
}
/** /**
* Implements hook_preprocess_HOOK() for html.tpl.php. * Implements hook_preprocess_HOOK() for html.tpl.php.
*/ */
......
...@@ -4,3 +4,40 @@ function_template_override: ...@@ -4,3 +4,40 @@ function_template_override:
_content: '\Drupal\theme_test\ThemeTestController::functionTemplateOverridden' _content: '\Drupal\theme_test\ThemeTestController::functionTemplateOverridden'
requirements: requirements:
_permission: 'access content' _permission: 'access content'
theme_test_info_stylesheets:
pattern: '/theme-test/info/stylesheets'
defaults:
_content: '\Drupal\theme_test\ThemeTestController::testInfoStylesheets'
requirements:
_access: 'TRUE'
theme_test_template_test:
pattern: '/theme-test/template-test'
defaults:
_content: '\Drupal\theme_test\ThemeTestController::testTemplate'
requirements:
_access: 'TRUE'
theme_test_suggestion:
pattern: '/theme-test/suggestion'
defaults:
_content: '\Drupal\theme_test\ThemeTestController::testSuggestion'
_title: 'Suggestion'
requirements:
_access: 'TRUE'
theme_test_alter:
pattern: '/theme-test/alter'
defaults:
_content: '\Drupal\theme_test\ThemeTestController::testAlter'
_title: 'Suggestion'
requirements:
_access: 'TRUE'
theme_test_request_listener:
pattern: '/theme-test/request-listener'
defaults:
_content: '\Drupal\theme_test\ThemeTestController::testRequestListener'
requirements:
_access: 'TRUE'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment