diff --git a/core/modules/block/block.admin.inc b/core/modules/block/block.admin.inc
index f94ce25..0b0edd4 100644
--- a/core/modules/block/block.admin.inc
+++ b/core/modules/block/block.admin.inc
@@ -8,16 +8,6 @@
use Drupal\block\Plugin\Core\Entity\Block;
/**
- * Page callback: Attaches CSS for the block region demo.
- *
- * @see block_menu()
- */
-function block_admin_demo($theme = NULL) {
- drupal_add_css(drupal_get_path('module', 'block') . '/block.admin.css');
- return '';
-}
-
-/**
* Page callback: Shows the block administration page.
*
* @param string $theme
diff --git a/core/modules/block/block.module b/core/modules/block/block.module
index d94ec3b..869a88a 100644
--- a/core/modules/block/block.module
+++ b/core/modules/block/block.module
@@ -170,19 +170,16 @@ function block_menu() {
'access arguments' => array($key),
'file' => 'block.admin.inc',
);
- $items['admin/structure/block/demo/' . $key] = array(
- 'title' => check_plain($theme->info['name']),
- 'page callback' => 'block_admin_demo',
- 'page arguments' => array($key),
- 'type' => MENU_CALLBACK,
- 'access callback' => '_block_themes_access',
- 'access arguments' => array($key),
- 'theme callback' => '_block_custom_theme',
- 'theme arguments' => array($key),
- 'file' => 'block.admin.inc',
- );
}
}
+ if (isset($theme)) {
+ $items['admin/structure/block/demo/%'] = array(
+ 'route_name' => 'block_admin_demo',
+ 'type' => MENU_CALLBACK,
+ 'theme callback' => '_block_custom_theme',
+ 'theme arguments' => array(4),
+ );
+ }
return $items;
}
@@ -191,7 +188,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.
@@ -234,9 +230,8 @@ 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 ($item['path'] != 'admin/structure/block/demo/%' || $item['map'][4] != $theme) {
// Load all region content assigned via blocks.
foreach (array_keys($all_regions) as $region) {
// Assign blocks to region.
@@ -256,26 +251,23 @@ function block_page_build(&$page) {
}
else {
// Append region description if we are rendering the regions demo page.
- $item = menu_get_item();
- if ($item['path'] == 'admin/structure/block/demo/' . $theme) {
- $visible_regions = array_keys(system_region_list($theme, REGIONS_VISIBLE));
- foreach ($visible_regions as $region) {
- $description = '
' . $all_regions[$region] . '
';
- $page[$region]['block_description'] = array(
- '#markup' => $description,
- '#weight' => 15,
- );
- }
- $page['page_top']['backlink'] = array(
- '#type' => 'link',
- '#title' => t('Exit block region demonstration'),
- '#href' => 'admin/structure/block' . (config('system.theme')->get('default') == $theme ? '' : '/list/' . $theme),
- // Add the "overlay-restore" class to indicate this link should restore
- // the context in which the region demonstration page was opened.
- '#options' => array('attributes' => array('class' => array('block-demo-backlink', 'overlay-restore'))),
- '#weight' => -10,
+ $visible_regions = array_keys(system_region_list($theme, REGIONS_VISIBLE));
+ foreach ($visible_regions as $region) {
+ $description = '' . $all_regions[$region] . '
';
+ $page[$region]['block_description'] = array(
+ '#markup' => $description,
+ '#weight' => 15,
);
}
+ $page['page_top']['backlink'] = array(
+ '#type' => 'link',
+ '#title' => t('Exit block region demonstration'),
+ '#href' => 'admin/structure/block' . (config('system.theme')->get('default') == $theme ? '' : '/list/' . $theme),
+ // Add the "overlay-restore" class to indicate this link should restore
+ // the context in which the region demonstration page was opened.
+ '#options' => array('attributes' => array('class' => array('block-demo-backlink', 'overlay-restore'))),
+ '#weight' => -10,
+ );
}
}
diff --git a/core/modules/block/block.routing.yml b/core/modules/block/block.routing.yml
index af247b0..2603497 100644
--- a/core/modules/block/block.routing.yml
+++ b/core/modules/block/block.routing.yml
@@ -4,3 +4,11 @@ block_admin_block_delete:
_form: '\Drupal\block\Form\AdminBlockDeleteForm'
requirements:
_permission: 'administer blocks'
+
+block_admin_demo:
+ pattern: '/admin/structure/block/demo/{theme}'
+ defaults:
+ _content: '\Drupal\block\Controller\AdminController::demo'
+ requirements:
+ _access_block_theme: 'TRUE'
+ _permission: 'administer blocks'
diff --git a/core/modules/block/lib/Drupal/block/Access/DemoThemesAccessCheck.php b/core/modules/block/lib/Drupal/block/Access/DemoThemesAccessCheck.php
new file mode 100644
index 0000000..d1879b2
--- /dev/null
+++ b/core/modules/block/lib/Drupal/block/Access/DemoThemesAccessCheck.php
@@ -0,0 +1,32 @@
+getRequirements());
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function access(Route $route, Request $request) {
+ return drupal_theme_access($request->attributes->get('theme'));
+ }
+}
diff --git a/core/modules/block/lib/Drupal/block/Controller/AdminController.php b/core/modules/block/lib/Drupal/block/Controller/AdminController.php
new file mode 100644
index 0000000..dff20a3
--- /dev/null
+++ b/core/modules/block/lib/Drupal/block/Controller/AdminController.php
@@ -0,0 +1,41 @@
+attributes->get('theme')])) {
+ throw new NotFoundHttpException();
+ }
+
+ $theme = $themes[$request->attributes->get('theme')];
+
+ // @todo Remove use of drupal_set_title() when
+ // http://drupal.org/node/1871596 is in.
+ drupal_set_title(t($theme->info['name']), PASS_THROUGH);
+ drupal_add_css(drupal_get_path('module', 'block') . '/block.admin.css');
+ return new Response();
+ }
+
+}