From 8e7ead4c05ff66772481b7ca343e993f328ff722 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Mon, 27 May 2013 18:11:03 -0500 Subject: [PATCH] Issue #1985570 by plopesc: Convert layout_test_page() to a Controller. --- core/modules/layout/tests/layout_test.module | 37 ---------- .../layout/tests/layout_test.routing.yml | 6 ++ .../Controller/LayoutTestController.php | 70 +++++++++++++++++++ 3 files changed, 76 insertions(+), 37 deletions(-) create mode 100644 core/modules/layout/tests/layout_test.routing.yml create mode 100644 core/modules/layout/tests/lib/Drupal/layout_test/Controller/LayoutTestController.php diff --git a/core/modules/layout/tests/layout_test.module b/core/modules/layout/tests/layout_test.module index 0e84a950997..b7a707349da 100644 --- a/core/modules/layout/tests/layout_test.module +++ b/core/modules/layout/tests/layout_test.module @@ -5,43 +5,6 @@ * Layout testing module. */ -/** - * Implementation of hook_menu(). - */ -function layout_test_menu() { - $items = array(); - $items['layout-test'] = array( - 'title' => 'Layout test', - 'page callback' => 'layout_test_page', - 'access callback' => TRUE, - ); - return $items; -} - -/** - * Page callback for layout testing. - */ -function layout_test_page() { - // Hack to enable and apply the theme to this page and manually invoke its - // layout plugin and render it. - global $theme; - $theme = 'layout_test_theme'; - theme_enable(array($theme)); - - $display = entity_load('display', 'test_twocol'); - $layout = $display->getLayoutInstance(); - - // @todo This tests that the layout can render its regions, but does not test - // block rendering: http://drupal.org/node/1812720. - // Add sample content in the regions that is looked for in the tests. - $regions = $layout->getRegions(); - foreach ($regions as $region => $info) { - $regions[$region] = '

' . $info['label'] . '

'; - } - - return $layout->renderLayout(FALSE, $regions); -} - /** * Implements hook_system_theme_info(). */ diff --git a/core/modules/layout/tests/layout_test.routing.yml b/core/modules/layout/tests/layout_test.routing.yml new file mode 100644 index 00000000000..636e13feb7c --- /dev/null +++ b/core/modules/layout/tests/layout_test.routing.yml @@ -0,0 +1,6 @@ +layout_test_page: + pattern: '/layout-test' + defaults: + _content: '\Drupal\layout_test\Controller\LayoutTestController::layoutTestPage' + requirements: + _access: 'TRUE' diff --git a/core/modules/layout/tests/lib/Drupal/layout_test/Controller/LayoutTestController.php b/core/modules/layout/tests/lib/Drupal/layout_test/Controller/LayoutTestController.php new file mode 100644 index 00000000000..bd6ee5f0192 --- /dev/null +++ b/core/modules/layout/tests/lib/Drupal/layout_test/Controller/LayoutTestController.php @@ -0,0 +1,70 @@ +entityStorageController = $entity_storage_controller; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static($container->get('plugin.manager.entity')->getStorageController('display')); + } + + /** + * Displays basic page for layout testing purposes. + * + * @return string + * An HTML string representing the contents of layout_test page. + */ + public function layoutTestPage() { + // Hack to enable and apply the theme to this page and manually invoke its + // layout plugin and render it. + global $theme; + $theme = 'layout_test_theme'; + theme_enable(array($theme)); + + $displays = $this->entityStorageController->load(array('test_twocol')); + $display = reset($displays); + $layout = $display->getLayoutInstance(); + + // @todo This tests that the layout can render its regions, but does not test + // block rendering: http://drupal.org/node/1812720. + // Add sample content in the regions that is looked for in the tests. + $regions = $layout->getRegions(); + foreach ($regions as $region => $info) { + $regions[$region] = '

' . $info['label'] . '

'; + } + + return $layout->renderLayout(FALSE, $regions); + } + +}