diff --git a/core/modules/block/block.admin.inc b/core/modules/block/block.admin.inc index af99b1a..1e70ca6 100644 --- a/core/modules/block/block.admin.inc +++ b/core/modules/block/block.admin.inc @@ -9,19 +9,6 @@ use Drupal\Core\Template\Attribute; /** - * Page callback: Attaches CSS for the block region demo. - * - * @see block_menu() - */ -function block_admin_demo($theme = NULL) { - return array( - '#attached' => array( - 'css' => array(drupal_get_path('module', 'block') . '/css/block.admin.css'), - ), - ); -} - -/** * Page callback: Build the block instance add form. * * @param string $plugin_id diff --git a/core/modules/block/block.module b/core/modules/block/block.module index ca13d32..e194eae 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -160,19 +160,16 @@ function block_menu() { 'type' => $key == $default_theme ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK, 'route_name' => 'block_admin_display.' . $plugin_id ); - $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; } @@ -181,7 +178,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. @@ -224,9 +220,10 @@ 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) { + // Make sure the blocks are not getting rendered for demo page + // or theme specific site building page. + if ($item['path'] != 'admin/structure/block/demo/%' || !isset($item['map'][4]) || $item['map'][4] != $theme) { // Load all region content assigned via blocks. foreach (array_keys($all_regions) as $region) { // Assign blocks to region. @@ -246,26 +243,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' . (\Drupal::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 635f4c2..245c06e 100644 --- a/core/modules/block/block.routing.yml +++ b/core/modules/block/block.routing.yml @@ -12,3 +12,10 @@ block_admin_display: entity_type: 'block' 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' diff --git a/core/modules/block/block.services.yml b/core/modules/block/block.services.yml index 9b6b40d..02c161b 100644 --- a/core/modules/block/block.services.yml +++ b/core/modules/block/block.services.yml @@ -18,3 +18,7 @@ services: class: Drupal\block\Access\BlockThemeAccessCheck tags: - { name: access_check} + access_check.block.demo: + class: Drupal\block\Access\DemoThemesAccessCheck + tags: + - { name: access_check } 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..6f58c01 --- /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 user_access('administer blocks') && 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..694b52d --- /dev/null +++ b/core/modules/block/lib/Drupal/block/Controller/AdminController.php @@ -0,0 +1,37 @@ +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 ''; + } +}