diff --git a/core/modules/block_place/block_place.module b/core/modules/block_place/block_place.module
index 563960f..e3532bd 100644
--- a/core/modules/block_place/block_place.module
+++ b/core/modules/block_place/block_place.module
@@ -6,6 +6,7 @@
*/
use Drupal\Core\Routing\RouteMatchInterface;
+use Drupal\Core\Url;
/**
* Implements hook_help().
@@ -14,7 +15,7 @@ function block_place_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.block_place':
$output = '
' . t('About') . '
';
- $output .= '' . t('The Place Blocks module module allows you to place blocks from every page. For more information, see the online documentation for the Place Blocks module.', array(':blocks-documentation' => 'https://www.drupal.org/documentation/modules/block_place/')) . '
';
+ $output .= '' . t('The Place Blocks module module allows you to place blocks from every page. For more information, see the online documentation for the Place Blocks module.', [':blocks-documentation' => 'https://www.drupal.org/documentation/modules/block_place/']) . '
';
$output .= '' . t('Uses') . '
';
$output .= '' . t('Block placement is specific to each theme on your site. This module allows you to place blocks in the context of your content pages') . '
';
return $output;
@@ -26,9 +27,7 @@ function block_place_help($route_name, RouteMatchInterface $route_match) {
*/
function block_place_toolbar() {
// Link to the current page with a query parameter.
- $url = \Drupal\Core\Url::fromRoute('');
- $request = \Drupal::request();
- $query = $request->query->all();
+ $query = \Drupal::request()->query->all();
if (isset($query['block-place-destination'])) {
$title = t('Cancel place block');
$description = t('Cancel placing a block on the page.');
@@ -41,27 +40,27 @@ function block_place_toolbar() {
// link in escapeAdmin.js.
$query['block-place-destination'] = '1';
}
- $url->setOption('query', $query);
+
// The 'Home' tab is a simple link, with no corresponding tray.
- $items['block_place'] = array(
+ $items['block_place'] = [
'#cache' => [
'contexts' => ['user.permissions', 'url.query_args'],
],
'#type' => 'toolbar_item',
- 'tab' => array(
+ 'tab' => [
'#access' => \Drupal::currentUser()->hasPermission('administer blocks'),
'#type' => 'link',
'#title' => $title,
- '#url' => $url,
- '#attributes' => array(
+ '#url' => Url::fromRoute('', [], ['query' => $query]),
+ '#attributes' => [
'title' => $description,
- 'class' => array('toolbar-icon', 'toolbar-icon-system-admin-structure'),
- ),
- ),
- '#wrapper_attributes' => array(
- 'class' => array('block-place-toolbar-tab'),
- ),
+ 'class' => ['toolbar-icon', 'toolbar-icon-system-admin-structure'],
+ ],
+ ],
+ '#wrapper_attributes' => [
+ 'class' => ['block-place-toolbar-tab'],
+ ],
'#weight' => 100,
- );
+ ];
return $items;
}
diff --git a/core/modules/block_place/block_place.services.yml b/core/modules/block_place/block_place.services.yml
index e442aca..95d7375 100644
--- a/core/modules/block_place/block_place.services.yml
+++ b/core/modules/block_place/block_place.services.yml
@@ -4,4 +4,3 @@ services:
arguments: ['@request_stack', '@current_user']
tags:
- { name: event_subscriber }
-
diff --git a/core/modules/block_place/src/EventSubscriber/BlockPlaceEventSubscriber.php b/core/modules/block_place/src/EventSubscriber/BlockPlaceEventSubscriber.php
index a1cb842..05116a2 100644
--- a/core/modules/block_place/src/EventSubscriber/BlockPlaceEventSubscriber.php
+++ b/core/modules/block_place/src/EventSubscriber/BlockPlaceEventSubscriber.php
@@ -48,10 +48,8 @@ public function __construct(RequestStack $request_stack, AccountInterface $accou
*/
public function onBlockPageDisplayVariantSelected(PageDisplayVariantSelectionEvent $event) {
if ($event->getPluginId() === 'block_page') {
- if ($this->requestStack->getCurrentRequest()->query->get('block-place-destination')) {
- if ($this->account->hasPermission('administer blocks')) {
- $event->setPluginId('block_place_page');
- }
+ if ($this->requestStack->getCurrentRequest()->query->has('block-place-destination') && $this->account->hasPermission('administer blocks')) {
+ $event->setPluginId('block_place_page');
}
$event->addCacheContexts(['user.permissions', 'url.query_args']);
}
@@ -60,7 +58,7 @@ public function onBlockPageDisplayVariantSelected(PageDisplayVariantSelectionEve
/**
* {@inheritdoc}
*/
- static function getSubscribedEvents() {
+ public static function getSubscribedEvents() {
// Set a very low priority, so that it runs last.
$events[RenderEvents::SELECT_PAGE_DISPLAY_VARIANT][] = ['onBlockPageDisplayVariantSelected', -1000];
return $events;
diff --git a/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php b/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php
index 88e1daf..eeb9efd 100644
--- a/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php
+++ b/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php
@@ -13,10 +13,7 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
- * Provides a page display variant that decorates the main content with blocks.
- *
- * @see \Drupal\Core\Block\MainContentBlockPluginInterface
- * @see \Drupal\Core\Block\MessagesBlockPluginInterface
+ * Allows blocks to be placed directly within a region.
*
* @PageDisplayVariant(
* id = "block_place_page",
@@ -40,7 +37,7 @@ class PlaceBlockPageVariant extends BlockPageVariant {
protected $routeMatch;
/**
- * Constructs a new BlockPageVariant.
+ * Constructs a new PlaceBlockPageVariant.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
@@ -48,21 +45,22 @@ class PlaceBlockPageVariant extends BlockPageVariant {
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
- * @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
- * The theme manager.
* @param \Drupal\block\BlockRepositoryInterface $block_repository
* The block repository.
* @param \Drupal\Core\Entity\EntityViewBuilderInterface $block_view_builder
* The block view builder.
* @param string[] $block_list_cache_tags
* The Block entity type list cache tags.
+ * @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
+ * The theme manager.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*/
- public function __construct(array $configuration, $plugin_id, $plugin_definition, ThemeManagerInterface $theme_manager, BlockRepositoryInterface $block_repository, EntityViewBuilderInterface $block_view_builder, array $block_list_cache_tags, RouteMatchInterface $route_match) {
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, BlockRepositoryInterface $block_repository, EntityViewBuilderInterface $block_view_builder, array $block_list_cache_tags, ThemeManagerInterface $theme_manager, RouteMatchInterface $route_match) {
+ parent::__construct($configuration, $plugin_id, $plugin_definition, $block_repository, $block_view_builder, $block_list_cache_tags);
+
$this->themeManager = $theme_manager;
$this->routeMatch = $route_match;
- parent::__construct($configuration, $plugin_id, $plugin_definition, $block_repository, $block_view_builder, $block_list_cache_tags);
}
/**
@@ -73,10 +71,10 @@ public static function create(ContainerInterface $container, array $configuratio
$configuration,
$plugin_id,
$plugin_definition,
- $container->get('theme.manager'),
$container->get('block.repository'),
- $container->get('entity.manager')->getViewBuilder('block'),
- $container->get('entity.manager')->getDefinition('block')->getListCacheTags(),
+ $container->get('entity_type.manager')->getViewBuilder('block'),
+ $container->get('entity_type.manager')->getDefinition('block')->getListCacheTags(),
+ $container->get('theme.manager'),
$container->get('current_route_match')
);
}
@@ -86,20 +84,23 @@ public static function create(ContainerInterface $container, array $configuratio
*/
public function build() {
$build = parent::build();
+
$active_theme = $this->themeManager->getActiveTheme();
$theme_name = $active_theme->getName();
$visible_regions = $this->getVisibleRegionNames($theme_name);
+
// Build an array of the region names in the right order.
- $empty = array_fill_keys($active_theme->getRegions(), array());
- $build += $empty;
+ $build += array_fill_keys($active_theme->getRegions(), []);
+
foreach (Element::children($build) as $region) {
if (!isset($visible_regions[$region])) {
continue;
}
+
$operations['block_description'] = [
'#type' => 'inline_template',
'#template' => '{{ region_name }} {{ link }}
',
- '#context' => array(
+ '#context' => [
'region_name' => $visible_regions[$region],
'link' => Link::createFromRoute($this->t('Place block'), 'block.admin_library', ['theme' => $theme_name], [
'query' => [
@@ -113,9 +114,8 @@ public function build() {
'width' => 700,
]),
],
- ]
- )->toString()
- ),
+ ]),
+ ],
];
$build[$region] = ['block_place_operations' => $operations] + $build[$region];
}
@@ -135,4 +135,5 @@ public function build() {
protected function getVisibleRegionNames($theme) {
return system_region_list($theme, REGIONS_VISIBLE);
}
+
}
diff --git a/core/modules/block_place/src/Tests/BlockPlaceTest.php b/core/modules/block_place/src/Tests/BlockPlaceTest.php
index 6d53a99..d452e67 100644
--- a/core/modules/block_place/src/Tests/BlockPlaceTest.php
+++ b/core/modules/block_place/src/Tests/BlockPlaceTest.php
@@ -8,7 +8,7 @@
/**
* Tests the placing a block.
*
- * @group block
+ * @group block_place
*/
class BlockPlaceTest extends WebTestBase {
@@ -17,36 +17,37 @@ class BlockPlaceTest extends WebTestBase {
*
* @var array
*/
- public static $modules = array('block', 'block_place', 'toolbar');
+ public static $modules = ['block', 'block_place', 'toolbar'];
/**
- * Ensure contextual links are disabled in Seven theme.
+ * Tests placing blocks as an admin and anonymous user.
*/
- function testSevenAdminTheme() {
+ function testPlacingBlocks() {
// Create administrative user.
- $admin_user = $this->drupalCreateUser([
+ $this->drupalLogin($this->drupalCreateUser([
'access administration pages',
'access toolbar',
'administer blocks',
'view the administration theme',
- ]);
- $this->drupalLogin($admin_user);
+ ]));
$this->drupalGet(Url::fromRoute(''));
- $this->assertLink(t('Place block'));
- $this->clickLink(t('Place block'));
+ $this->assertLink('Place block');
+ $this->clickLink('Place block');
+
$this->assertLinkByHref('admin/structure/block/library/classy?region=content');
- $this->assertLink(t('Cancel place block'));
- $this->drupalLogout();
+ $this->assertLink('Cancel place block');
+
// Create a user who cannot administer blocks.
- $other_user = $this->drupalCreateUser([
+ $this->drupalLogin($this->drupalCreateUser([
'access administration pages',
'access toolbar',
'view the administration theme',
- ]);
- $this->drupalLogin($other_user);
+ ]));
$this->drupalGet(Url::fromRoute(''));
- $this->assertNoLink(t('Place block'));
+ $this->assertNoLink('Place block');
+
$this->drupalGet('admin/structure/block/library/classy');
$this->assertResponse(403);
}
+
}