Skip to content
Snippets Groups Projects
Commit 491bd633 authored by Angie Byron's avatar Angie Byron
Browse files

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

parent 0aa6f4e5
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -7,28 +7,89 @@
namespace Drupal\theme_test;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Controller\ControllerBase;
/**
* 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) {
return new static();
public function functionTemplateOverridden() {
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(
'#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() {
*/
function theme_test_menu() {
$items['theme-test/suggestion'] = array(
'title' => 'Suggestion',
'page callback' => '_theme_test_suggestion',
'access callback' => TRUE,
'route_name' => 'theme_test_suggestion',
'theme callback' => '_theme_custom_theme',
'type' => MENU_CALLBACK,
);
$items['theme-test/alter'] = array(
'title' => 'Suggestion',
'page callback' => '_theme_test_alter',
'access callback' => TRUE,
'theme callback' => '_theme_custom_theme',
'type' => MENU_CALLBACK,
);
$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,
'route_name' => 'theme_test_alter',
'type' => MENU_CALLBACK,
);
$items['theme-test/function-template-overridden'] = array(
......@@ -80,7 +61,6 @@ function theme_test_menu() {
);
return $items;
}
/**
* Fake registry loading callback.
*/
......@@ -89,39 +69,6 @@ function _theme_test_load_registry() {
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.
*/
......@@ -129,26 +76,6 @@ function _theme_custom_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.
*/
......
......@@ -4,3 +4,40 @@ function_template_override:
_content: '\Drupal\theme_test\ThemeTestController::functionTemplateOverridden'
requirements:
_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'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment