Commit c9e8fe36 authored by alexpott's avatar alexpott
Browse files

Issue #1987636 by kgoel, tim.plunkett, pdrake, vijaycs85, pguillard, jibran:...

Issue #1987636 by kgoel, tim.plunkett, pdrake, vijaycs85, pguillard, jibran: Convert block_admin_demo() to a new style controller.
parent 69a83341
<?php
/**
* @file
* Admin page callbacks for the block module.
*/
use Drupal\block\Entity\Block;
use Drupal\Core\Template\Attribute;
/**
* Page callback: Attaches CSS for the block region demo.
*
* @see block_menu()
*
* @deprecated Use \Drupal\block\Controller\BlockController::demo()
*/
function block_admin_demo($theme = NULL) {
return array(
'#attached' => array(
'library' => array(
array('block', 'drupal.block.admin'),
),
),
);
}
......@@ -7,6 +7,7 @@
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Component\Utility\NestedArray;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
/**
* Denotes that a block is not enabled in any region and should not be shown.
......@@ -135,7 +136,6 @@ function block_menu() {
'route_name' => "block.admin_display_$key",
);
$items["admin/structure/block/demo/$key"] = array(
'title' => check_plain($theme->info['name']),
'route_name' => 'block.admin_demo',
'type' => MENU_CALLBACK,
'theme callback' => '_block_custom_theme',
......@@ -150,7 +150,6 @@ function block_menu() {
*
* Path:
* - admin/structure/block/list/% (for each theme)
* - admin/structure/block/demo/% (for each theme)
*
* @param $theme
* Either the name of a theme or a full theme object.
......@@ -193,9 +192,7 @@ function block_page_build(&$page) {
// Fetch a list of regions for the current theme.
$all_regions = system_region_list($theme);
$item = menu_get_item();
if ($item['path'] != 'admin/structure/block/demo/' . $theme) {
if (\Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_NAME) != 'block.admin_demo') {
// Load all region content assigned via blocks.
foreach (array_keys($all_regions) as $region) {
// Assign blocks to region.
......
......@@ -7,17 +7,34 @@
namespace Drupal\block\Controller;
use Drupal\Component\Utility\String;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
/**
* Controller routines for block routes.
* Controller routines for admin block routes.
*/
class BlockController {
class BlockController extends ControllerBase {
/**
* @todo Remove block_admin_demo().
* Returns a block theme demo page.
*
* @param string $theme
* The name of the theme.
*
* @return array
* A render array containing the CSS and title for the block region demo.
*/
public function demo($theme) {
module_load_include('admin.inc', 'block');
return block_admin_demo($theme);
$themes = list_themes();
return array(
'#title' => String::checkPlain($themes[$theme]->info['name']),
'#attached' => array(
'library' => array(
array('block', 'drupal.block.admin'),
),
),
);
}
}
......@@ -67,6 +67,17 @@ function setUp() {
}
}
/**
* Test block demo page exists and functions correctly.
*/
public function testBlockDemoUiPage() {
$this->drupalPlaceBlock('system_help_block', array('region' => 'help'));
$this->drupalGet('admin/structure/block');
$this->clickLink(t('Demonstrate block regions (@theme)', array('@theme' => 'Stark')));
$elements = $this->xpath('//div[contains(@class, "region-highlighted")]/div[contains(@class, "block-region") and contains(text(), :title)]', array(':title' => 'Highlighted'));
$this->assertTrue(!empty($elements), 'Block demo regions are shown.');
}
/**
* Test block admin page exists and functions correctly.
*/
......
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