diff --git a/core/modules/block/block.admin.inc b/core/modules/block/block.admin.inc index 953e462..61dec39 100644 --- a/core/modules/block/block.admin.inc +++ b/core/modules/block/block.admin.inc @@ -22,23 +22,6 @@ function block_admin_demo($theme = NULL) { } /** - * Page callback: Shows the block administration page. - * - * @param string $theme - * The theme to display the administration page for. - * - * @return array - * A render array for a page containing a list of blocks. - * - * @see block_menu() - */ -function block_admin_display($theme) { - return Drupal::entityManager() - ->getListController('block') - ->render($theme); -} - -/** * 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 cdec2b8..3db6b7f 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -117,10 +117,7 @@ function block_menu() { $items['admin/structure/block'] = array( 'title' => 'Blocks', 'description' => 'Configure what block content appears in your site\'s sidebars and other regions.', - 'page callback' => 'block_admin_display', - 'page arguments' => array($default_theme), - 'access arguments' => array('administer blocks'), - 'file' => 'block.admin.inc', + 'route_name' => 'block_admin_display' ); $items['admin/structure/block/add/%/%'] = array( 'title' => 'Configure block', @@ -160,11 +157,8 @@ function block_menu() { $theme = $themes[$key]; $items['admin/structure/block/list/' . $plugin_id] = array( 'title' => check_plain($theme->info['name']), - 'page arguments' => array($key), 'type' => $key == $default_theme ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK, - 'access callback' => '_block_themes_access', - 'access arguments' => array($key), - 'file' => 'block.admin.inc', + 'route_name' => 'block_admin_display.' . $plugin_id ); $items['admin/structure/block/demo/' . $key] = array( 'title' => check_plain($theme->info['name']), diff --git a/core/modules/block/block.routing.yml b/core/modules/block/block.routing.yml index af247b0..68e58b6 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_display: + pattern: '/admin/structure/block' + defaults: + _content: '\Drupal\block\Controller\BlockListController::listing' + entity_type: 'block' + requirements: + _permission: 'administer blocks' diff --git a/core/modules/block/block.services.yml b/core/modules/block/block.services.yml index 745bf66..f059b3d 100644 --- a/core/modules/block/block.services.yml +++ b/core/modules/block/block.services.yml @@ -9,3 +9,12 @@ services: factory_method: get factory_service: cache_factory arguments: [block] + block.route_subscriber: + class: Drupal\block\Routing\RouteSubscriber + tags: + - { name: event_subscriber} + arguments: ['@plugin.manager.system.plugin_ui'] + block.theme_access_check: + class: Drupal\block\Access\BlockThemeAccessCheck + tags: + - { name: access_check} diff --git a/core/modules/block/lib/Drupal/block/Access/BlockThemeAccessCheck.php b/core/modules/block/lib/Drupal/block/Access/BlockThemeAccessCheck.php new file mode 100644 index 0000000..4612396 --- /dev/null +++ b/core/modules/block/lib/Drupal/block/Access/BlockThemeAccessCheck.php @@ -0,0 +1,34 @@ +getRequirements()); + } + + /** + * {@inheritdoc} + */ + public function access(Route $route, Request $request) { + $theme = $request->attributes->get('theme'); + return user_access('administer blocks') && drupal_theme_access($theme); + } + +} diff --git a/core/modules/block/lib/Drupal/block/Controller/BlockListController.php b/core/modules/block/lib/Drupal/block/Controller/BlockListController.php new file mode 100644 index 0000000..38a8de0 --- /dev/null +++ b/core/modules/block/lib/Drupal/block/Controller/BlockListController.php @@ -0,0 +1,67 @@ +entityManager = $entity_manager; + $this->configFactory = $config_factory; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.entity'), + $container->get('config.factory') + ); + } + + /** + * Shows the block administration page. + * + * @param string $entity_type + * Entity type of list page. + * @param string|null $theme + * Theme key of block list. + * + * @return array|string + * A render array as expected by drupal_render(). + */ + public function listing($entity_type, $theme = NULL) { + $default_theme = $theme ?: $this->configFactory->get('system.theme')->get('default'); + return $this->entityManager->getListController($entity_type)->render($default_theme); + } + +} diff --git a/core/modules/block/lib/Drupal/block/Routing/RouteSubscriber.php b/core/modules/block/lib/Drupal/block/Routing/RouteSubscriber.php new file mode 100644 index 0000000..7c6f77e --- /dev/null +++ b/core/modules/block/lib/Drupal/block/Routing/RouteSubscriber.php @@ -0,0 +1,69 @@ +plugin_manager = $plugin_manager; + } + /** + * Implements EventSubscriberInterface::getSubscribedEvents(). + */ + static function getSubscribedEvents() { + $events[RoutingEvents::DYNAMIC] = 'routes'; + return $events; + } + + /** + * Generate dynamic routes for various block pages. + * + * @param \Drupal\Core\Routing\RouteBuildEvent $event + * The route building event. + * + * @return \Symfony\Component\Routing\RouteCollection + * The route collection that contains the new dynamic route. + */ + public function routes(RouteBuildEvent $event) { + $collection = $event->getRouteCollection(); + foreach ($this->plugin_manager->getDefinitions() as $plugin_id => $plugin) { + list($plugin_base, $key) = explode(':', $plugin_id); + if ($plugin_base == 'block_plugin_ui') { + $route = new Route('admin/structure/block/list/' . $plugin_id, array( + '_controller' => '\Drupal\block\Controller\BlockListController::listing', + 'entity_type' => 'block', + 'theme' => $key, + ),array( + '_block_themes_access' => 'TRUE', + )); + $collection->add('block_admin_display.' . $plugin_id , $route); + } + } + } +} diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php index 90df426..5990b2f 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php @@ -27,7 +27,7 @@ class BlockStorageUnitTest extends DrupalUnitTestBase { * * @var array */ - public static $modules = array('block', 'block_test'); + public static $modules = array('block', 'block_test', 'system'); /** * The block storage controller.